About delete, delete[], operator delete(), etc
<blockquote>
  <p><strong>Possible Duplicates:</strong><br>
  <a href="http://stackoverflow.com/questions/197675/how-does-delete-know-the-size-of-the-operand-array">How does delete[] &ldquo;know&rdquo; the size of the operand array?</a><br>
  <a href="http://stackoverflow.com/questions/1553382/pod-freeing-memory-is-delete-equal-to-delete">( POD )freeing memory : is delete[] equal to delete ?</a>  </p>
</blockquote>



<p>As I understand, the following</p>

<pre><code>class A {};
A* a = new A;
//
delete A;
</code></pre>

<p>will result first in a call to <code>operator new()</code> (the global one, or a specialized one provided by A) to allocate the right amount of memory and then to a call to the constructor of A. And when <code>delete</code> is called, is will first call the destructor of A, and then call <code>operator delete()</code> to deallocate the "right amount of memory".</p>

<p>As I read in TC++PL, this "right amount of memory" is determined like that:</p>

<blockquote>
  <p>To deallocate space allocated by new, delete and delete[] must be able to determine the size of the object allocated. This implies that an object allocated using the standard implementation of new will occupy slightly more space than a static object. Typically, one word is used to hold the object's size.</p>
</blockquote>

<p>This makes sense. But where is this word stored to be accessible by <code>delete</code> ? Just before the address pointed by the new pointer ? So that <code>delete</code> can obtain the size to be deleted by accessing <code>a-sizeof&lt;void*&gt;</code> ?</p>

<p>Can you clarify this ?</p>

<p>I think the answer to that may help me to understand how <code>delete []</code> works. I understand how <code>new []</code> will work, and that <code>delete []</code> will first call the destructors for "all the objects of the array" and the deallocate all this memory... </p>

<p>But how can <code>delete []</code> know the size of the array ?</p>

<p>Thanks for your helpful answers !</p>
