How can I make my app to use less memory
-
Hi, I have some problems with my apps memory usage. They use a lot of memory. How can I make my app to use less memory? Does it matter if I use semantic { CMyClass c; : } or { CMyClass *c; c = new CMyClass(); : delete c; } Do Windows use some kind of garbage collection? Then my app has been running for a while the memory usage is lesser. Why? Grateful for all help I can get. /Ola Carlsson, Sweden
-
Hi, I have some problems with my apps memory usage. They use a lot of memory. How can I make my app to use less memory? Does it matter if I use semantic { CMyClass c; : } or { CMyClass *c; c = new CMyClass(); : delete c; } Do Windows use some kind of garbage collection? Then my app has been running for a while the memory usage is lesser. Why? Grateful for all help I can get. /Ola Carlsson, Sweden
The amount of memory required by a CMyClass object is the same, regardless of whether it's used on the stack or the heap. Garbage collection in VC++ is non-existant. If you use the heap, use it wisely. If I have a given object new'd/deleted many times, I will usually redesign the app so that the class is defined as a global variable and new'd in InitInstance, and deleted in the app destructor. Of course, this assumes that you don't need more than a single instance of the class object. Each app's requirements are different. Last item of note - I'm not sure if there's a limit on the size of the stack in a 32-bit program. In 16-bit days, it was 64k, so you had to be very careful of what data you put there. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
-
Hi, I have some problems with my apps memory usage. They use a lot of memory. How can I make my app to use less memory? Does it matter if I use semantic { CMyClass c; : } or { CMyClass *c; c = new CMyClass(); : delete c; } Do Windows use some kind of garbage collection? Then my app has been running for a while the memory usage is lesser. Why? Grateful for all help I can get. /Ola Carlsson, Sweden
Ola Carlsson wrote: Does it matter if I use semantic [...] Yes. If you're using heap memory your app will have larger memory footprint. There are a number of ways you can reduce the memory size of your executable, but they always boils down to: know what you're doing and what your compiler and runtime library is doing for you. Do Windows use some kind of garbage collection? Absolutely not. That's your responsibility. Then my app has been running for a while the memory usage is lesser. Why? There could be a number of reasons. One of them could be that you just looked at what was currently committed to RAM and not the total Working Set. When you minimize any app its working set is "trimmed" (SetProcessWorkingSetsize(-1, -1); IIRC).
-
The amount of memory required by a CMyClass object is the same, regardless of whether it's used on the stack or the heap. Garbage collection in VC++ is non-existant. If you use the heap, use it wisely. If I have a given object new'd/deleted many times, I will usually redesign the app so that the class is defined as a global variable and new'd in InitInstance, and deleted in the app destructor. Of course, this assumes that you don't need more than a single instance of the class object. Each app's requirements are different. Last item of note - I'm not sure if there's a limit on the size of the stack in a 32-bit program. In 16-bit days, it was 64k, so you had to be very careful of what data you put there. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 Please review the Legal Disclaimer in my bio. ------- signature ends
John Simmons / outlaw programmer wrote: Last item of note - I'm not sure if there's a limit on the size of the stack in a 32-bit program. There is no limit here, except when the virtual memory for stack bottom reaches something else (such as a heap). Then it will surely go down in flames. :-) It can AFAIK be changed by e.g. linker flags (changing the PE flags), but to my knowledge it has never been used in production applications.