Collecting yet more references for implementing a custom heap for C++. One of the issues you run into when using a custom heap is the notion of placement new: void *operator new (size_t size, Heap &heap) { return heap.Allocate(size); }
Object allocations now appear so:
Heap local; obj *p = new (local) obj();
And when deleting the memory you must ensure that you give it back to the heap:
operator delete(p, local);
That last part makes the system less friendly. You can however override the operator new and delete for ‘obj’ and give it knoledge of a local heap.
More references:
- Memory management in C++
- C++ in action book (overloading operator new)
- Using C++ Objects in a Handle-Based