akintayo
akintayo

Reputation: 176

How to track the memory usage in C++

I have a C++ program running under linux. Is it possible to track its memory usage from the code? I am allocating new objects and running out of memory, so I want to keep track of how quickly I am using memory.

Thanks

Upvotes: 3

Views: 3198

Answers (4)

Šimon Tóth
Šimon Tóth

Reputation: 36451

Valgrinds module massif is exactly what you are looking for.

http://valgrind.org/docs/manual/ms-manual.html

Upvotes: 4

fredoverflow
fredoverflow

Reputation: 263320

You could try my experimental heap debugger ;-)

Upvotes: 0

dash-tom-bang
dash-tom-bang

Reputation: 17853

http://www.paulnettle.com/ click "code" then "MMGR" then the graphic that says "CODE" in red letters.

MMGR drops into your project. Include it in any source files where you want comprehensive memory tracking and it does the rest. It really is quite amazing despite the uselessness of his website.

Upvotes: 1

Jerry Coffin
Jerry Coffin

Reputation: 490573

You could overload ::operator new to track the memory usage (normally, everything else goes through this).

Upvotes: 1

Related Questions