Getting the memory usage

Started by
13 comments, last by podferio 13 years, 9 months ago
im using windows vista. I linked the Psapi.lib in Project Propertes>Linker>General>Add Addition Library Directories

Also tried Clean and Build but its still the same.
Advertisement
Do you want to know the runtime memory use or the static size of the function as inside the executable?

Remember that operating systems talk about memory in terms of pages usually, so IIRC you are going to have a granularity of ~4KB or so. This also seems like it might be premature micro-optimisation.
Quote:Original post by podferio
im using windows vista. I linked the Psapi.lib in Project Propertes>Linker>General>Add Addition Library Directories

Also tried Clean and Build but its still the same.


A .lib file isn't a directory. You need to add it to the linker input settings in the list of "Additional Dependencies".
Quote:Original post by _moagstar_
You need to link with Psapi.lib

That's why i included the compiler options "cl <file> /link PsApi.lib".[smile]
Also, you can check MSDN for what header to #include and what lib to link with.
[Window Detective] - Windows UI spy utility for programmers
Quote:Original post by rip-off
Remember that operating systems talk about memory in terms of pages usually, so IIRC you are going to have a granularity of ~4KB or so.
This, and in addition, you have no really reliable value in there.

You can get the number of reserved pages, which is likely much higher than what you actually use, since the runtime will reserve memory in big chunks for less overhead.

Or you can get the size of the working set, which is more close to the memory actually used (within the 4k granularity), but not necessarily so. It is possible that some pages were purged from the working set to make room for other memory that you used. You can only be more or less sure that this isn't the case if you set your minimum working set size to some huge value first, so all your pages will stay in memory (and even then, you are strictly not guaranteed that it works as desired, because the OS has no obligation to actually do what you ask for).

The only reliable way of knowing how much memory a given piece of code is using is to override allocators (... and to add the maximum stack size).
Thank you so much for all your help guys. Finally build my program without errors. ;)

-james

This topic is closed to new replies.

Advertisement