|
Because in the
std::string b = t;
example the compiler, under the hood, is calling the string contructor instead of the assignment operator. You can test the following little change:
std::string b;
b = t;
BTW to be honest, I missed your first example, before .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
first takes "copy constructor" while the second takes "assignment operator". string doesnot have copy constructor that takes char.
to avoid ambiguity in "assignment operator" specify explicit typecast.
m.s = std::string(t);
|
|
|
|
|
Hello experts,
I have the need to create a small, non-GUI application, which would consume no more than 300k~320k of memory...
My code should also have the ability to use Win32 API.
When I tried a "Win32 Application" project, even with no more than an empty WinMain() function, it consumes about 1000k of RAM...
BTW, I use windows Task Manager to read memory consumption...
What kind of project should I create?
Any guidelines?
I know C++ as a language, but have never actually written anything with it...
Thanks in advance,
Shy.
|
|
|
|
|
Shy Agam wrote: have the need to create a small, non-GUI application, which would consume no more than 300k~320k of memory...
Why?.
(i.e. do you really need such a strict contraint?)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I was asked to write the app... It's no me who decide...
|
|
|
|
|
Try (I didn't make a test) to change the STACK linker option [^] that defaults to 1 MB .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi,
How about console application?
Best Regards,
Suman
|
|
|
|
|
I've created an empty console project, added a new .cpp file, and written the following code:
#include <windows.h>
void main()
{
Sleep(10000);
} This simple code uses 600k of RAM...
Furthermore, it opens a console window, but I suppose it's possible to hide it...
|
|
|
|
|
In generated code, check which part displays console.
Is "windows.h" the only header included or something else?
Try not including header except which needed for Win32 API.
Best Regards,
Suman
|
|
|
|
|
rp_suman wrote: In generated code, check which part displays console.
What do you mean by "In generated code"?
Nothing was auto-generated...
rp_suman wrote: Is "windows.h" the only header included or something else?
Yes, it's the only header included.
However, when I included it and linked the project, basetsd.h was automatically added to the project as an external dependency.
|
|
|
|
|
Which version of vc++ you are trying?
I am not sure, but there may be difference in memory between different versions of vc++(6.0, 7.0 and 8.0).
|
|
|
|
|
|
Shy Agam wrote: even with no more than an empty WinMain() function, it consumes about 1000k of RAM
Are you sure, how did you measure this?
|
|
|
|
|
Using the "Processes" tab in the Task Manager...
|
|
|
|
|
If I am not wrong the "Mem Usage" column of the task manager includes shared memory from loaded DLLs.
|
|
|
|
|
My goal is to make the Mem Usage column display 320k or less...
|
|
|
|
|
Shy Agam wrote: My goal is to make the Mem Usage column display 320k or less...
Even though that is not the memory that the application will consume?
Who is repsonsible for those requirements, would he consider using a root kit that hides the presence of the process from the task manager? Just kidding... you are misinterpreting the data returned from the task manager. What you see there is something like the size of the virtual address space in use which includes system DLLs... but no empty WinMain() application will use up 320K free system memory, how could an empty program waste multiple KB? See How big is my program[^].
Hope it helps
/M
modified on Saturday, March 22, 2008 10:53 AM
|
|
|
|
|
Moak wrote: Who is repsonsible for those requirements, would he consider using a root kit that hides the presence of the process from the task manager? Just kidding...
Hehe... That was funny...
There's an existing app which consumes about 300k.
It's basically the same as the one I'm supposed to write, but it lacks some basic must-have features/abilities, and needs some improvements...
The goal is to keep this kind of memory usage, but improve the app, in order not to "pay a large price" for the improvements...
|
|
|
|
|
Shy Agam, I modified my last answer with a link to an article here on CP. Please have a look.
/M
|
|
|
|
|
I read the article... Thanks...
|
|
|
|
|
Moak could be right, task manager may show not only the program size but linked DLLs etc..
You make sure, the memory size means runtime memory shown by task manager or just the exe file size.
Whats the exe file size?
Best Regards,
Suman
btw, my vc 2005 trial version has been expired, so I could not try, just telling ideas
|
|
|
|
|
It doesn't matter... I was put on certain constraints... I have to enforce them...
Maybe I can remove dependencies from my app...(?)
According to previous posts, it should affact the MemUsage column...
|
|
|
|
|
Hi,
All the best to solve the problem!!
Please let me know when you find solution
Best Regards,
Suman
|
|
|
|
|
Shy Agam wrote: I was put on certain constraints... I have to enforce them...
That's all well and good, but you must use the right tool to measure with. Task Manager is not that tool.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello All,
How to get present Date Time in MFC application?
Thanks
|
|
|
|