title: C++ new memory allocation fragmentation
body: <p>I was trying to look at the behavior of the new allocator and why it doesn't place data contiguously. </p>
  
  <p>My code:</p>
  
  <pre><code>struct ci {
      char c;
      int i;
  }
  
  template &lt;typename T&gt;
  void memTest()
  {
      T * pLast = new T();
      for(int i = 0; i &lt; 20; ++i) {
           T * pNew = new T();
           cout &lt;&lt; (pNew - pLast) &lt;&lt; " ";
           pLast = pNew;
      }
  }
  </code></pre>
  
  <p>So I ran this with char, int, ci. Most allocations were a fixed length from the last, sometimes there were odd jumps from one available block to another.</p>
  
  <p>sizeof(char) : 1<br>
  Average Jump: 64 bytes</p>
  
  <p>sizeof(int): 4<br>
  Average Jump: 16</p>
  
  <p>sizeof(ci): 8 (int has to be placed on a 4 byte align)<br>
  Average Jump: 9</p>
  
  <p>Can anyone explain why the allocator is fragmenting memory like this? Also why is the jump for char so much larger then ints and a structure that contains both an int and char.  </p>