LokiAllocator for STL containers.

Developers
2008-03-19
2013-04-08
  • Richard Sposato

    Richard Sposato - 2008-03-19

    Loki now has a class which wraps the small object allocator to act as an allocator for STL containers.

    You can find it inside ./include/loki/Allocator.h.

    To use LokiAllocator, just declare your STL container as something akin to this:
    typedef ::std::vector< TestResult, ::Loki::LokiAllocator< TestResult > > Results;

    Cheers & Thank you!

    Rich

     
  • Won-ku Lee

    Won-ku Lee - 2009-09-19

    LokiAllocator work very well.

    But, I have a question about that.
    In &lt;Allocator.h&gt; line 90 and 97, LokiAllocator::allocate just call AllocT::Allocate() with count* sizeof( Type ).

    is always right? .. count*sizeof(Type)

    I counldn't find a definition of STL allocator that is like &quot;Chunk be alloced together must be dealloced together, too.&quot;

     
  • Richard Sposato

    Richard Sposato - 2009-09-24

    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

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks