I’m writing cross platform C++ code (Windows, Mac). Is there a way to check how much memory is in use by the current process? A very contrived snippet to illustrate:
unsigned long m0 = GetMemoryInUse(); char *p = new char[ random_number ]; unsigned long m1 = GetMemoryInUse(); printf( '%d bytes used\n', (m1-m0) );
Of course (m1-m0) should equal random_number, but I’m trying to do this on a more complicated level, including possible library calls that could allocate memory.
The following are not preferable:
- Use Valgrind (or its ilk)
- Use a custom memory allocator to track allocated memory.
1 Answer