Understanding Massif Memory Usage Measurements

closed account (LyTXjE8b)
I've recently been attempting the problems on CodeEval.com, where solutions are rated on execution time and maximum memory usage. However, I've found the memory measurements quite variable (on the same code) and I'm trying to understand if my code is at fault or if the site's profiling setup is.

I compiled the following program with g++ and profiled its memory usage using Valgrind's massif.
1
2
3
4
5
#include <iostream>
int main(int, const char*[]) {
  std::cout << "Hello World!" << std::endl;
  return 0;
}

The executable measured 22 288B on disk. Using massif with its default options (only profiling the heap), the max heap usage was 72 712B. Finally usage massif with --pages-as-heap=yes, the maximum total memory usage was measured at around ~15MB.

Am I misusing massif or misunderstanding the output? If not, how does such a simple 20kB program manage to use so much memory? Does the 15MB figure include all shared libraries linked to? Even if it does, surely that's just libstdc++ in this case?

I apologise if this post is a bit vague, but I'm at a loss about this and am not sure how to be more specific with my question.
Last edited on
Topic archived. No new replies allowed.