Custom heap allocator - the allocated object must point back to allocator?

Viewed 541

In environment that has many instances of custom heap allocators,
are the following statements correct? :-

  1. Each allocated pointer should be encapsulated in a type (e.g. Ptr)
    that cache pointer of who allocated me (Allo*) e.g.

    class Ptr={     
        Allo* alloPtr;  //<-- to keep track
        public: void delete(){ 
            //call back to something like "a.deallocate()"
        }
    }
    Allo a;   //a custom allocator
    Ptr<X> x=a.allocate<X>();
    x.delete();  
    

    I think I need to do that to make delete() easier.

  2. If the allocator is more complex, e.g. internally keep a lot of chunks :-

    enter image description here

    Ptr should keep track which chunk it resides on, OR
    there must be some tiny flag before the allocated content :-

    enter image description here

    Otherwise, I have to iterate each chunk to find the address -> low performance.

Sorry if this is too newbie, I am very new to custom allocators.
It is not homework - I am trying to improve my game library.

I have read :-

1 Answers
Related