Allocator for STL

Help
Won-ku Lee
2009-09-21
2013-04-08
  • Won-ku Lee
    Won-ku Lee
    2009-09-21

    Hi.

    I couldn't found standard that may explain chunks be allocated together must be deallocate together.

    But' loki-allocator for STL just use count*size(T) for new memory block size.

    Is it right?

    Please answer me…

     
  • The allocate and deallocate functions in LokiAllocator must allow for arrays.

        // Make an array of 10 Things.
        Thing * myThings = new Thing;
        // Now deallocate the array.
        delete  myThings;

    Section 5.3.4  and Section 5.3.5  of the C++ Standard describe array allocation and deallocation.

    Line 5 in Section 20.4.1.1 allocator members explicitly says to multiply the count by the sizeof the type to determine how much memory to allocate for arrays.  Line 8 says the count for deallocate should be the same value as that passed into allocate.  This means the C++ Standard wants to make sure arrays of objects are allocated and deallocated together.

    I hope that answers your question.  If not, could you please clarify what you meant?

    Cheers,

    Rich

     
  • Won-ku Lee
    Won-ku Lee
    2009-09-24

    Thank you very much for your help.

    You are so kind.