What is the best way to measure memory from a program?

I am trying to optimize the Windows program that I am developing, trying to find the best data structures that minimize memory usage. It loads large blocks of data, so with huge files it can use a large amount of RAM.

To measure memory, I use GlobalMemoryStatusEx. See: http://msdn.microsoft.com/en-us/library/aa366589(VS.85).aspx

I believe this works for most Windows accessories, from Windows 2000 all the way to Windows Vista.

Is this the preferred way to measure memory usage from a program, or is there another, better way?


Addenum: found a question about Stackoverflow: How to get memory usage under Windows in C ++ that references GetProcessMemoryInfo

I'll try to do that.

+3
source share
3 answers

See addenum in my question.

+1
source

If you are trying to optimize your own program memory, I suggest you use a memory profiling tool. There are many there ... some of them are free, some of them ... you will surely find the one you need. These tools are written specifically for what you need (as well as to search for memory leaks), so ... it will be difficult to compare and do something like this yourself from your own program :)

+1
source

I use valgrind to track memory usage, as well as profile code and detect memory leaks. I think the array tool keeps track of memory usage on the stack and heap.

0
source

All Articles