1

In C++, with this:

std::time_t first  = time(NULL);
/* .. code .. */
std::time_t second = time(NULL);

std::cout << "Seg : " << difftime(second,first) << std::endl; 

I can determine my program's execution duration.

Can I determine its memory consumption at different points through the program?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
JuanPablo
  • 23,792
  • 39
  • 118
  • 164
  • For what platform? You're going to have to write something platform specific to do this... – Jerry Coffin Apr 22 '11 at 04:07
  • Are you talking about stack space, or heap memory? – EboMike Apr 22 '11 at 04:08
  • @EboMike: Or perhaps he's using an environment that employs something other than a heap for the free store. The language doesn't care what it is. – Lightness Races in Orbit Apr 22 '11 at 04:16
  • 2
    Override the basic `new` operators and count the memory used. Voila, you got your mechanism ;) ... you can also use profilers with or without instrumentation to achieve the same. – 0xC0000022L Apr 22 '11 at 04:22
  • You can read your own `/proc/self/statm`, see `man proc`. You should be aware that a program doesn't normally release memory to the operating system when a `free`, `realloc`-down or `delete` is done... it only grows memory when more is needed. Linux is a bit smarter, and may special case really big allocations, releasing them before process termination. Consequently, it will be more useful to concentrate on which program steps caused memory to grow suddenly. – Tony Delroy Apr 22 '11 at 05:48
  • @Tomalak: Prescriptive pedantry much? :) – GManNickG Apr 22 '11 at 06:54
  • 1
    @GMan: How many milligrams do you want, sir? Sincerely, Doctor C++ – Lightness Races in Orbit Apr 22 '11 at 12:10
  • @EboMike both, stack space, or heap memory. – JuanPablo Apr 22 '11 at 20:37

1 Answers1

2

Not easily.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055