#include <SmallObj.h>
Inheritance diagram for Loki::SmallObjAllocator:
Public Member Functions | |
void * | Allocate (std::size_t size, bool doThrow) |
void | Deallocate (void *p, std::size_t size) |
void | Deallocate (void *p) |
std::size_t | GetMaxObjectSize () const |
Returns max # of bytes which this can allocate. | |
std::size_t | GetAlignment () const |
Returns # of bytes between allocation boundaries. | |
bool | TrimExcessMemory (void) |
bool | IsCorrupt (void) const |
Protected Member Functions | |
SmallObjAllocator (std::size_t pageSize, std::size_t maxObjectSize, std::size_t objectAlignSize) | |
~SmallObjAllocator (void) |
Loki::SmallObjAllocator::SmallObjAllocator | ( | std::size_t | pageSize, | |
std::size_t | maxObjectSize, | |||
std::size_t | objectAlignSize | |||
) | [protected] |
The only available constructor needs certain parameters in order to initialize all the FixedAllocator's. This throws only if
pageSize | # of bytes in a page of memory. | |
maxObjectSize | Max # of bytes which this may allocate. | |
objectAlignSize | # of bytes between alignment boundaries. |
Loki::SmallObjAllocator::~SmallObjAllocator | ( | void | ) | [protected] |
Destructor releases all blocks, all Chunks, and FixedAllocator's. Any outstanding blocks are unavailable, and should not be used after this destructor is called. The destructor is deliberately non-virtual because it is protected, not public.
void * Loki::SmallObjAllocator::Allocate | ( | std::size_t | size, | |
bool | doThrow | |||
) |
Allocates a block of memory of requested size. Complexity is often constant-time, but might be O(C) where C is the number of Chunks in a FixedAllocator.
size | # of bytes needed for allocation. | |
doThrow | True if this should throw if unable to allocate, false if it should provide no-throw exception safety level. |
void Loki::SmallObjAllocator::Deallocate | ( | void * | p | ) |
Deallocates a block of memory at a given place but of unknown size size. Complexity is O(F + C) where F is the count of FixedAllocator's in the pool, and C is the number of Chunks in all FixedAllocator's. This does not throw exceptions. This overloaded version of Deallocate is called by the nothow delete operator - which is called when the nothrow new operator is used, but a constructor throws an exception.
void Loki::SmallObjAllocator::Deallocate | ( | void * | p, | |
std::size_t | size | |||
) |
Deallocates a block of memory at a given place and of a specific size. Complexity is almost always constant-time, and is O(C) only if it has to search for which Chunk deallocates. This never throws.
bool Loki::SmallObjAllocator::IsCorrupt | ( | void | ) | const |
Returns true if anything in implementation is corrupt. Complexity is O(F + C + B) where F is the count of FixedAllocator's in the pool, C is the number of Chunks in all FixedAllocator's, and B is the number of blocks in all Chunks. If it determines any data is corrupted, this will return true in release version, but assert in debug version at the line where it detects the corrupted data. If it does not detect any corrupted data, it returns false.
bool Loki::SmallObjAllocator::TrimExcessMemory | ( | void | ) |
Releases empty Chunks from memory. Complexity is O(F + C) where F is the count of FixedAllocator's in the pool, and C is the number of Chunks in all FixedAllocator's. This will never throw. This is called by AllocatorSingleto::ClearExtraMemory, the new_handler function for Loki's allocator, and is called internally when an allocation fails.