Public Member Functions | |
| void | add () |
| a chunk has been given back | |
| CChunk () | |
| uint | getBlockSizeWithOverhead () const |
| CNode & | getNode (uint index) |
| void | grab () |
| a chunk has been taken | |
| void | init (CFixedSizeAllocator *fsa) |
| ~CChunk () | |
Data Fields | |
| CFixedSizeAllocator * | Allocator |
| uint8 * | Mem |
| uint | NumFreeObjs |
|
|
Definition at line 94 of file fixed_size_allocator.cpp. References Allocator, and NumFreeObjs.
00095 {
00096 NumFreeObjs = 0;
00097 Allocator = NULL;
00098 }
|
|
|
Definition at line 101 of file fixed_size_allocator.cpp. References NLMISC::CFixedSizeAllocator::_NumChunks, Allocator, getNode(), NLMISC::CFixedSizeAllocator::getNumBlockPerChunk(), nlassert, NumFreeObjs, uint, and NLMISC::CFixedSizeAllocator::CNode::unlink().
|
|
|
a chunk has been given back
Definition at line 154 of file fixed_size_allocator.cpp. References NLMISC::CFixedSizeAllocator::_NumChunks, Allocator, NLMISC::CFixedSizeAllocator::getNumBlockPerChunk(), nlassert, and NumFreeObjs. Referenced by NLMISC::CFixedSizeAllocator::CNode::link().
00155 {
00156 nlassert(Allocator);
00157 // a node of this chunk has been given back
00158 nlassert(NumFreeObjs < Allocator->getNumBlockPerChunk());
00159 ++ NumFreeObjs;
00160 if (NumFreeObjs == Allocator->getNumBlockPerChunk()) // all objects back ?
00161 {
00162 if (Allocator->_NumChunks > 1) // we want to have at least one chunk left
00163 {
00164 delete this; // kill that object
00165 }
00166 }
00167 }
|
|
|
Definition at line 88 of file fixed_size_allocator.cpp. References Allocator, NLMISC::CFixedSizeAllocator::getNumBytesPerBlock(), and uint. Referenced by getNode(), and init().
00089 {
00090 return std::max(sizeof(CNode) - offsetof(CNode, Next), Allocator->getNumBytesPerBlock()) + offsetof(CNode, Next);
00091 }
|
|
|
Definition at line 146 of file fixed_size_allocator.cpp. References Allocator, getBlockSizeWithOverhead(), NLMISC::CFixedSizeAllocator::getNumBlockPerChunk(), index, nlassert, uint, and uint8. Referenced by init(), and ~CChunk().
00147 {
00148 nlassert(Allocator);
00149 nlassert(index < Allocator->getNumBlockPerChunk());
00150 return *(CNode *) ((uint8 *) Mem + index * getBlockSizeWithOverhead());
00151 }
|
|
|
a chunk has been taken
Definition at line 170 of file fixed_size_allocator.cpp. References nlassert, and NumFreeObjs. Referenced by NLMISC::CFixedSizeAllocator::CNode::unlink().
00171 {
00172 // a node of this chunk has been given back
00173 nlassert(NumFreeObjs > 0);
00174 -- NumFreeObjs;
00175 }
|
|
|
init all the element as a linked list Definition at line 115 of file fixed_size_allocator.cpp. References Allocator, NLMISC::CFixedSizeAllocator::CNode::Chunk, getBlockSizeWithOverhead(), getNode(), NLMISC::CFixedSizeAllocator::CNode::Next, nlassert, NumFreeObjs, NLMISC::CFixedSizeAllocator::CNode::Prev, uint, and uint8. Referenced by NLMISC::CFixedSizeAllocator::alloc().
00116 {
00117 nlassert(!Allocator);
00118 nlassert(alloc);
00119 Allocator = alloc;
00120 //
00121 Mem = new uint8[getBlockSizeWithOverhead() * alloc->getNumBlockPerChunk()];
00122 //
00123 getNode(0).Chunk = this;
00124 getNode(0).Next = &getNode(1);
00125 getNode(0).Prev = &alloc->_FreeSpace;
00126 //
00127 NumFreeObjs = alloc->getNumBlockPerChunk();
00129 for (uint k = 1; k < (NumFreeObjs - 1); ++k)
00130 {
00131 getNode(k).Chunk = this;
00132 getNode(k).Next = &getNode(k + 1);
00133 getNode(k).Prev = &getNode(k - 1).Next;
00134 }
00135
00136 getNode(NumFreeObjs - 1).Chunk = this;
00137 getNode(NumFreeObjs - 1).Next = alloc->_FreeSpace;
00138 getNode(NumFreeObjs - 1).Prev = &(getNode(NumFreeObjs - 2).Next);
00139
00140 if (alloc->_FreeSpace) { alloc->_FreeSpace->Prev = &getNode(NumFreeObjs - 1).Next; }
00141 alloc->_FreeSpace = &getNode(0);
00142 ++(alloc->_NumChunks);
00143 }
|
|
|
Definition at line 86 of file fixed_size_allocator.h. Referenced by add(), CChunk(), NLMISC::CFixedSizeAllocator::free(), getBlockSizeWithOverhead(), getNode(), init(), NLMISC::CFixedSizeAllocator::CNode::link(), and ~CChunk(). |
|
|
Definition at line 87 of file fixed_size_allocator.h. |
|
|
Definition at line 85 of file fixed_size_allocator.h. Referenced by add(), CChunk(), grab(), init(), NLMISC::CFixedSizeAllocator::CNode::unlink(), and ~CChunk(). |
1.3.6