title: Basic heap usage statistics in GCC on 64-bit platform
body: <p>I need to answer a basic question from inside my C program compiled by GCC for Linux: how much of process heap is currently in use (allocated by <code>malloc</code>) and how much resides if free heap blocks. GNU implementation of standard library has <code>mallinfo</code> function which reports exactly what I need, but it only usable with 32-bit configurations and, AFAIK, there's no 64-bit equivalent of that functionality (BTW, anyone knows why?).</p>
  
  <p>I use GCC on Linux, so I need this for Linux. But I assume that the heap is opaque to the system, so the only way to answer this question is to use the means provided by the implementation of the standard library. </p>
  
  <p>In MSVC implementation on Windows platform there's no equivalent of <code>mallinfo</code> function but there's so called <em>heap-walk</em> functionality, which allows one to calculate the necessary information by iterating through all blocks in the heap. AFAIK, there's no heap-walk interface in GNU C library. (Is there?).</p>
  
  <p>So, again, what do I do in GCC? It doesn't have to be efficient, meaning that the aforementioned heap-walk based approach would work perfectly fine for me. How do I find out how much heap is in use and how much is free in GCC? I can probably try installing malloc-hooks and "manually" track the sizes, although I'm not sure how to determine the current heap arena size (see <code>mallinfo.arena</code>) without using <code>mallinfo</code>.</p>