This allocator only frees the allocated memory when it is deleted.
This is a good allocator for building dictionaries, where we only add things to a container, but never remove them.
Definition at line 117 of file kcontainerallocators.h.
#include <kcontainerallocators.h>
Classes |
|
class | MemoryBlock |
Public Member Functions |
|
KHungryAllocator (size_t pRecordSize) | |
KHungryAllocator (const KHungryAllocator &pOther) | |
~KHungryAllocator () | |
void | Reserve (size_t const pRecordCount) |
void * | AllocateRecords (size_t const pRecordCount=1) |
void | FreeMemory (void *pRecord) |
size_t | GetRecordSize () const |
KHungryAllocator & | operator= (const KHungryAllocator &pOther) |
KHungryAllocator | ( | size_t | pRecordSize | ) | [inline] |
Definition at line 120 of file kcontainerallocators.h.
: mRecordSize(pRecordSize) , mData(NULL) , mRecordPoolSize(0) { }
KHungryAllocator | ( | const KHungryAllocator & | pOther | ) | [inline] |
Definition at line 127 of file kcontainerallocators.h.
: mRecordSize(pOther.mRecordSize) , mData(0) , mRecordPoolSize(pOther.mRecordPoolSize) { }
~KHungryAllocator | ( | ) | [inline] |
Definition at line 134 of file kcontainerallocators.h.
{ MemoryBlock* lCurrent = mData; MemoryBlock* lNext = lCurrent ? lCurrent->mNextBlock : 0; while (lCurrent) { FbxSdkDelete(lCurrent); lCurrent = lNext; lNext = lCurrent ? lCurrent->mNextBlock : 0; } }
void Reserve | ( | size_t const | pRecordCount | ) | [inline] |
Definition at line 146 of file kcontainerallocators.h.
{ MemoryBlock* lMem = FbxSdkNew< MemoryBlock >(pRecordCount * mRecordSize); lMem->mNextBlock = mData; mData = lMem; mRecordPoolSize += pRecordCount; }
void* AllocateRecords | ( | size_t const | pRecordCount = 1 |
) | [inline] |
Definition at line 154 of file kcontainerallocators.h.
{ MemoryBlock* lBlock = mData; void* lRecord = NULL; while ((lBlock != NULL) && ((lRecord = lBlock->GetChunk(pRecordCount * mRecordSize)) == NULL)) { lBlock = lBlock->mNextBlock; } if (lRecord == NULL) { size_t lNumRecordToAllocate = mRecordPoolSize / 8 == 0 ? 2 : mRecordPoolSize / 8; if (lNumRecordToAllocate < pRecordCount) { lNumRecordToAllocate = pRecordCount; } Reserve(lNumRecordToAllocate); lRecord = AllocateRecords(pRecordCount); } return lRecord; }
void FreeMemory | ( | void * | pRecord | ) | [inline] |
Definition at line 179 of file kcontainerallocators.h.
{
// "Hungry": release memory only when the allocator is destroyed.
}
size_t GetRecordSize | ( | ) | const [inline] |
Definition at line 184 of file kcontainerallocators.h.
{
return mRecordSize;
}
KHungryAllocator& operator= | ( | const KHungryAllocator & | pOther | ) | [inline] |
Definition at line 189 of file kcontainerallocators.h.
{ if( this != &pOther ) { // The next call to AllocateRecords() may skip over currently reserved // records if the size changes drastically, but otherwise GetChunk() // is size-oblivious. if( mRecordSize < pOther.mRecordSize ) { mRecordPoolSize = 0; } mRecordSize = pOther.mRecordSize; } return(*this); }