title: Why *must* delete[] and delete be different?
body: <p>I'm well aware that in C++, what <code>delete[]</code> is to <code>new[]</code>, <code>delete</code> is to <code>new</code>. This is not about C++ syntax. I am wondering about the <strong>reasons</strong> <code>delete[]</code> was defined as something distinct from the plain <code>delete</code>. What are the implementation reasons for this?</p>
  
  <p>Consider what happens with this code:</p>
  
  <pre><code>MyClass *object = new MyClass;
  delete object;
  </code></pre>
  
  <p>When <code>delete</code> is encountered the memory manager has to lookup the object pointer value in its allocation structure, whatever it is, and mark the corresponding <code>sizeof(MyClass)</code> chunk of memory as free.</p>
  
  <p>Now consider what happens with this code:</p>
  
  <pre><code>MyClass *array = new MyClass[ num_objects ];
  delete [] array;
  </code></pre>
  
  <p>When <code>delete</code> is encountered the memory manager has to lookup the array pointer value in its allocation structure, whatever it is, <strong>find <code>num_objects</code> value from that structure</strong> , and mark the corresponding <code>num_objects*sizeof(MyClass)</code> chunk of memory as free.</p>
  
  <p>Apart from <code>num_objects</code> being assumed 1 in the single object case and looked up in the internal data structure in the array case I don't see the difference. So why <code>delete</code> and <code>delete[]</code> couldn't have been spelled identically? </p>
  
  <p>In other words, what's wrong with</p>
  
  <pre><code>MyClass *object = new MyClass;
  </code></pre>
  
  <p>being implemented as</p>
  
  <pre><code>MyClass *object = new MyClass[1];
  </code></pre>
  
  <p>so that C++ syntax wouldn't have to make distinction between <code>delete</code> and <code>delete[]</code> ?</p>