csBlockAllocator< T, BlockPolicy > Class Template Reference
This class implements a memory allocator which can efficiently allocate objects that all have the same size. More...
#include <csutil/blockallocator.h>
Public Member Functions | |
T * | Alloc () |
Allocate a new object. | |
void | Compact () |
Compact the block allocator so that all blocks that are completely unused are removed. | |
csBlockAllocator (size_t nelem=32, bool warn_unfreed=false) | |
Construct a new block allocator. | |
void | Empty () |
Destroy all objects allocated by the pool. | |
void | Free (T *p) |
Deallocate an object. | |
size_t | GetBlockElements () const |
Query number of elements per block. | |
~csBlockAllocator () | |
Destroy all allocated objects and release memory. | |
Protected Member Functions | |
uint8 * | AllocBlock () const |
Allocate a block and initialize its free-node chain. | |
void | DestroyObject (T *p, bool warn=false) const |
Destroy an object, optionally warning if pedanticism is desired. | |
void | DisposeAll (bool warn_unfreed) |
Destroys all living objects and releases all memory allocated by the pool. | |
size_t | FindBlock (void const *m) const |
Find the memory block which contains the given memory. | |
void | FreeBlock (uint8 *p) const |
Dispose of a block. | |
csBitArray | GetAllocationMap () const |
Get a usage mask showing all used (1's) and free (0's) nodes in the entire allocator. | |
Static Protected Member Functions | |
static int | FuzzyCmp (uint8 *const &block, BlockKey const &k) |
Comparison function for FindBlock() which does a "fuzzy" search given an arbitrary address. | |
Protected Attributes | |
csArray< uint8 * > | blocks |
size_t | blocksize |
size_t | elsize |
FreeNode * | freenode |
bool | insideDisposeAll |
bool | pedantic |
size_t | size |
Classes | |
struct | BlockKey |
struct | FreeNode |
Detailed Description
template<class T, class BlockPolicy = csBlockAllocatorNormalBlockPolicy>
class csBlockAllocator< T, BlockPolicy >
This class implements a memory allocator which can efficiently allocate objects that all have the same size.
It has no memory overhead per allocation (unless the objects are smaller than sizeof(void*) bytes) and is extremely fast, both for Alloc() and Free(). The only restriction is that any specific allocator can be used for just one type of object (the type for which the template is instantiated).
- Remarks:
- The objects are properly constructed and destructed.
Assumes that the class
T
with which the template is instantiated has a default (zero-argument) constructor. Alloc() uses this constructor to initialize each vended object.Defining the macro CS_BLOCKALLOC_DEBUG will cause freed objects to be overwritten with '0xfb' bytes. This can be useful to track use of already freed objects, as they can be more easily recognized (as some members will be likely bogus.)
- See also:
- csArray
Definition at line 154 of file blockallocator.h.
Constructor & Destructor Documentation
|
Construct a new block allocator.
Definition at line 311 of file blockallocator.h. |
|
Destroy all allocated objects and release memory.
Definition at line 323 of file blockallocator.h. |
Member Function Documentation
|
Allocate a new object. Its default (no-argument) constructor is invoked. Definition at line 386 of file blockallocator.h. Referenced by csShaderVarBlockAlloc::Alloc(), csTree< T >::csTree(), csRedBlackTree< csRedBlackTreePayload< K, T > >::RecursiveCopy(), and csRedBlackTree< csRedBlackTreePayload< K, T > >::RecursiveInsert(). |
|
Allocate a block and initialize its free-node chain.
Definition at line 206 of file blockallocator.h. Referenced by csBlockAllocator< csBSPTree >::Alloc(). |
|
Compact the block allocator so that all blocks that are completely unused are removed. The blocks that still contain elements are not touched. Definition at line 342 of file blockallocator.h. |
|
Destroy an object, optionally warning if pedanticism is desired.
Definition at line 234 of file blockallocator.h. Referenced by csBlockAllocator< csBSPTree >::DisposeAll(), and csBlockAllocator< csBSPTree >::Free(). |
|
Destroys all living objects and releases all memory allocated by the pool.
Definition at line 272 of file blockallocator.h. Referenced by csBlockAllocator< csBSPTree >::Empty(), and csBlockAllocator< csBSPTree >::~csBlockAllocator(). |
|
Destroy all objects allocated by the pool.
Definition at line 333 of file blockallocator.h. Referenced by csRedBlackTree< csRedBlackTreePayload< K, T > >::DeleteAll(). |
|
Find the memory block which contains the given memory.
Definition at line 195 of file blockallocator.h. Referenced by csBlockAllocator< csBSPTree >::Free(), and csBlockAllocator< csBSPTree >::GetAllocationMap(). |
|
Deallocate an object. It is safe to provide a null pointer. Definition at line 408 of file blockallocator.h. Referenced by csTree< T >::Delete(), and csRedBlackTree< csRedBlackTreePayload< K, T > >::DeleteNode(). |
|
Dispose of a block.
Definition at line 226 of file blockallocator.h. Referenced by csBlockAllocator< csBSPTree >::Compact(), and csBlockAllocator< csBSPTree >::DisposeAll(). |
|
Comparison function for FindBlock() which does a "fuzzy" search given an arbitrary address. It checks if the address falls somewhere within a block rather than checking if the address exactly matches the start of the block (which is the only information recorded in blocks[] array). Definition at line 187 of file blockallocator.h. Referenced by csBlockAllocator< csBSPTree >::FindBlock(). |
|
Get a usage mask showing all used (1's) and free (0's) nodes in the entire allocator.
Definition at line 253 of file blockallocator.h. Referenced by csBlockAllocator< csBSPTree >::Compact(), and csBlockAllocator< csBSPTree >::DisposeAll(). |
|
Query number of elements per block.
Definition at line 420 of file blockallocator.h. |
The documentation for this class was generated from the following file:
- csutil/blockallocator.h
Generated for Crystal Space by doxygen 1.4.4