title: How do I programmatically check memory use in a fairly portable way? (C/C++)
body: <p>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:</p>
  
  <pre><code>unsigned long m0 = GetMemoryInUse();
  char *p = new char[ random_number ];
  unsigned long m1 = GetMemoryInUse();
  printf( "%d bytes used\n", (m1-m0) );
  </code></pre>
  
  <p>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.</p>
  
  <p>The following are not preferable:</p>
  
  <ol>
  <li>Use Valgrind (or its ilk) </li>
  <li>Use a custom memory allocator to track
  allocated memory.</li>
  </ol>