title: How are malloc and free implemented?
body: <p>I want to implement my own dynamic memory management system in order to add new features that help to manage memory in C++.</p>
  
  <p>I use Windows (XP) and Linux (Ubuntu).
  What is needed to implement functions like 'malloc' and 'free'?
  I think that I have to use lowest level system calls.</p>
  
  <p>For Windows, I have found the functions: GetProcessHeap, HeapAlloc, HeapCreate, HeapDestroy and HeapFree.</p>
  
  <p>For Linux, I have not found any system calls for heap management. On Linux, malloc and free are system calls, are not they?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit:</strong><br>
  C++ does not provide garbage collector and garbage collector is slow. Some allocations are easy to free, but there are allocations that needs a garbage collector.</p>
  
  <p>I want to implement these functions and add new features:<br>
  * Whenever free() be called, check if the pointer belongs to heap.<br>
  * Help with garbage collection. I have to store some information about the allocated block.<br>
  * Use multiple heaps (HeapCreate/HeapDestroy on Windows). I can delete an entire heap with its allocated blocks quickly.</p>