PDA

View Full Version : How to determine memory usage?



nopalot
11th February 2007, 17:21
Hi Folks,

i would like to monitor the memory usage of my application from inside my application. Is there a way to query the ammount of allocated memory? A cross platform approach would fit the most, since it's designed to run on linux and on windows.
Please let me know if you have any ideas.
Thanks in advance!

e8johan
11th February 2007, 17:25
I cannot see a way to do this in a cross platform manner - perhaps there is a posix call that I'm not aware of - so I'm not saying that there is no way.

For your Linux needs you can always rely on the /proc file system for finding this type of information. You find your PID using getpid (http://www.die.net/doc/linux/man/man2/getpid.2.html).

Methedrine
11th February 2007, 17:28
You could always overload the "new" operator and keep a log about how much memory was allocated.

wysota
11th February 2007, 20:50
You could always overload the "new" operator and keep a log about how much memory was allocated.

Not all memory is allocated using the new operator (and you'd have to do that for every class you use (templates might help)). It's better to redefine malloc() - it'll cover more cases. It won't be 100% foul proof though.