   [C++] custom placement delete[]
  Suppose we allocate an array on the heap using a custom placement new[] operator. How would we properly delete this memory?This is how it works for single objects:#define DAEVSGUI_ALLOCATE(object) new (DaevsGUI::heap) objecttemplate <class T>inlinevoid DAEVSGUI_DEALLOCATE(T *pointer){    pointer->~T();    DaevsGUI::heap->deallocate(pointer);}Now, how would I make sure the deconstructor of each array element is called? I don't know the size of the array when it's passed...how does the CPU know how much memory to get rid of anyways, when no size is given but just a pointer?#define DAEVSGUI_ALLOCATE_ARRAY(object, size) new (DaevsGUI::heap) object[size]template <class T>inlinevoid DAEVSGUI_DEALLOCATE_ARRAY(T *pointer){    //pointer->~T();    DaevsGUI::heap->deallocate_array(pointer);}PS: behind the scene:namespace DaevsGUI{    class Heap    {    public:   virtual void *allocate(size_t size);   virtual void deallocate(void *pointer);   virtual void *allocate_array(size_t size);   virtual void deallocate_array(void *pointer);    };    ////////////////////////////////////////////////////////////////    void *Heap::allocate(size_t size)    {   return operator new (size);    }    void Heap::deallocate(void *pointer)    {   operator delete (pointer);    }    void *Heap::allocate_array(size_t size)    {   return operator new[] (size);    }    void Heap::deallocate_array(void *pointer)    {   operator delete[] (pointer);    }    ////////////////////////////////////////////////////////////////}/////////////////////////////////////////////////////////////////**************************************************************/////////////////////////////////////////////////////////////////void *operator new (size_t size, DaevsGUI::Heap *iheap){    return iheap->allocate(size);}void operator delete (void *pointer, DaevsGUI::Heap *iheap){    iheap->deallocate(pointer);}void *operator new[] (size_t size, DaevsGUI::Heap *iheap){    return iheap->allocate_array(size);}void operator delete[] (void *pointer, DaevsGUI::Heap *iheap){    iheap->deallocate_array(pointer);}namespace DaevsGUI{    Heap _heap;    Heap *heap = &_heap;}
  The short answer is that the way placement new[] and delete[] are specified in the standard is broken. If you want to achieve the results of using the array form of placement new you'll need to handle allocation, deallocation, creation and destruction manually. That is, when you allocate, call your memory allocation function then call placement new for each individual object and when you deallocate manually call the destructor for each object and then manually deallocate the memory block.   