#include <fixed_size_allocator.h>
NB : number of blocks per chunks must be at least 3
: thread safety
Nevrax France
Definition at line 49 of file fixed_size_allocator.h.
Public Member Functions | |
| void * | alloc () |
| alloc a block | |
| CFixedSizeAllocator (uint numBytesPerBlock, uint numBlockPerChunk) | |
| void | free (void *block) |
| destroy and dealloc a block | |
| uint | getNumAllocatedBlocks () const |
| uint | getNumBlockPerChunk () const |
| uint | getNumBytesPerBlock () const |
| ~CFixedSizeAllocator () | |
Private Attributes | |
| CNode * | _FreeSpace |
| uint | _NumAlloc |
| uint | _NumBlockPerChunk |
| uint | _NumBytesPerBlock |
| uint | _NumChunks |
Friends | |
| class | CChunk |
| class | CNode |
|
||||||||||||
|
Definition at line 33 of file fixed_size_allocator.cpp. References _FreeSpace, _NumAlloc, _NumBlockPerChunk, _NumBytesPerBlock, _NumChunks, min, nlassert, and uint.
00034 {
00035 _FreeSpace = NULL;
00036 _NumChunks = 0;
00037 nlassert(numBytesPerBlock > 1);
00038 _NumBytesPerBlock = numBytesPerBlock;
00039 _NumBlockPerChunk = std::min(numBlockPerChunk, (uint) 3);
00040 _NumAlloc = 0;
00041 }
|
|
|
Definition at line 44 of file fixed_size_allocator.cpp. References _FreeSpace, _NumAlloc, _NumChunks, NLMISC::CFixedSizeAllocator::CNode::Chunk, nlassert, and nlwarning.
00045 {
00046 if (_NumAlloc != 0)
00047 {
00048 #ifdef NL_DEBUG
00049 nlwarning("%d blocks were not freed", (int) _NumAlloc);
00050 #endif
00051 return;
00052 }
00053 if (_NumChunks > 0)
00054 {
00055 nlassert(_NumChunks == 1);
00056 // delete the left chunk. This should force all the left nodes to be removed from the empty list
00057 delete _FreeSpace->Chunk;
00058 }
00059 }
|
|
|
alloc a block
Definition at line 62 of file fixed_size_allocator.cpp. References _FreeSpace, _NumAlloc, NLMISC::CFixedSizeAllocator::CChunk::init(), and NLMISC::CFixedSizeAllocator::CNode::unlink().
00063 {
00064 if (!_FreeSpace)
00065 {
00066 CChunk *chunk = new CChunk; // link a new chunk to that object
00067 chunk->init(this);
00068 }
00069 ++ _NumAlloc;
00070 return _FreeSpace->unlink();
00071 }
|
|
|
destroy and dealloc a block get the node from the object Definition at line 74 of file fixed_size_allocator.cpp. References _NumAlloc, NLMISC::CFixedSizeAllocator::CChunk::Allocator, NLMISC::CFixedSizeAllocator::CNode::Chunk, NLMISC::CFixedSizeAllocator::CNode::link(), nlassert, and uint8.
|
|
|
Definition at line 62 of file fixed_size_allocator.h. References _NumAlloc, and uint.
00062 { return _NumAlloc; }
|
|
|
Definition at line 60 of file fixed_size_allocator.h. References _NumBlockPerChunk, and uint. Referenced by NLMISC::CFixedSizeAllocator::CChunk::add(), NLMISC::CFixedSizeAllocator::CChunk::getNode(), and NLMISC::CFixedSizeAllocator::CChunk::~CChunk().
00060 { return _NumBlockPerChunk; }
|
|
|
Definition at line 59 of file fixed_size_allocator.h. References _NumBytesPerBlock, and uint. Referenced by NLMISC::CFixedSizeAllocator::CChunk::getBlockSizeWithOverhead().
00059 { return _NumBytesPerBlock; }
|
|
|
Definition at line 104 of file fixed_size_allocator.h. |
|
|
Definition at line 105 of file fixed_size_allocator.h. |
|
|
Definition at line 107 of file fixed_size_allocator.h. Referenced by alloc(), CFixedSizeAllocator(), NLMISC::CFixedSizeAllocator::CNode::link(), and ~CFixedSizeAllocator(). |
|
|
Definition at line 114 of file fixed_size_allocator.h. Referenced by alloc(), CFixedSizeAllocator(), free(), getNumAllocatedBlocks(), and ~CFixedSizeAllocator(). |
|
|
Definition at line 112 of file fixed_size_allocator.h. Referenced by CFixedSizeAllocator(), and getNumBlockPerChunk(). |
|
|
Definition at line 111 of file fixed_size_allocator.h. Referenced by CFixedSizeAllocator(), and getNumBytesPerBlock(). |
|
|
Definition at line 108 of file fixed_size_allocator.h. Referenced by NLMISC::CFixedSizeAllocator::CChunk::add(), CFixedSizeAllocator(), NLMISC::CFixedSizeAllocator::CChunk::~CChunk(), and ~CFixedSizeAllocator(). |
1.3.6