title: Per thread memory allocation
body: <p>I am working on a trace tool for multithread applications, more especially about memory allocation.</p>
  
  <p>I would like a per thread memory allocation. I know that when a thread do a malloc, the memory used is the global heap. I would like to trace which thread allocated how much memory.</p>
  
  <p>I did a wrapper upon malloc, incrementing values each time there is a malloc as:</p>
  
  <pre><code>void *mymalloc(size_t size) {
      mem_used[thread_id] += size;
      return malloc(size);
  }
  </code></pre>
  
  <p>It works well. The problem is with <code>free</code> method, which does not return how much memory is released.</p>
  
  <p>Don't take into account my solution, it is just to show what I tried.</p>
  
  <p>EDIT:</p>
  
  <p>As mentionned above, keeping my own table is a too heavy method.</p>