title: Overloading delete and retrieving size?
body: <p>I am currently writing a small custom memory Allocator in C++, and want to use it together with operator overloading of <code>new</code>/ <code>delete</code>. Anyways, my memory Allocator basically checks if the requested memory is over a certain threshold, and if so uses malloc to allocate the requested memory chunk. Otherwise the memory will be provided by some <code>fixedPool</code> allocators. that generally works, but for my deallocation function looks like this:</p>
  
  <pre><code>void MemoryManager::deallocate(void * _ptr, size_t _size){
      if(_size &gt; heapThreshold)
          deallocHeap(_ptr);
      else 
          deallocFixedPool(_ptr, _size);
  }
  </code></pre>
  
  <p>So I need to provide the size of the chunk pointed to, to deallocate from the right place.</p>
  
  <p>Now the problem is that the delete keyword does not provide any hint on the size of the deleted chunk, so I would need something like this:</p>
  
  <pre><code>void operator delete(void * _ptr, size_t _size){ 
      MemoryManager::deallocate(_ptr, _size); 
  }
  </code></pre>
  
  <p>But as far as I can see, there is no way to determine the size inside the delete operator.- If I want to keep things the way it is right now, would I have to save the size of the memory chunks myself?</p>