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!
LokiAllocator work very well.
But, I have a question about that.
In <Allocator.h> 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 "Chunk be alloced together must be dealloced together, too."
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.
Section 5.3.4 and Section 5.3.5 of the C++ Standard describe array allocation and deallocation.
Line 5 in Section 18.104.22.168 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?
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.