I’m using valgrind to check that my program is within the required memory bounds for a class. When I run massif, I get a pretty chart that says my max memory usage (heap+stack) is 21 KB. When I run valgrind’s memcheck, it tells me I allocated 185931 bytes. What’s the difference in what they’re reporting? If it matters, there’s a step in my code where I cat two strings, so I resize the first one with realloc, strcat the two strings, and then free the second.
Share
Memcheck is aimed at looking for memory leaks, so it counts the total of all memory allocations (and the total of all frees).
Massif is aimed at looking at the memory footprint of the program, so it counts the total memory in use at each point in the program.
In other words, if your program looks like this:
Then Memcheck will tell you this:
Whereas Massif will tell you this:
(Over the life of the program, 20480 bytes were allocated; but the peak usage was only 10240 bytes).