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 155 of file blockallocator.h.
Constructor & Destructor Documentation
|
Construct a new block allocator.
Definition at line 312 of file blockallocator.h. |
|
Destroy all allocated objects and release memory.
Definition at line 324 of file blockallocator.h. |
Member Function Documentation
|
Allocate a new object. Its default (no-argument) constructor is invoked. Definition at line 387 of file blockallocator.h. Referenced by csShaderVarBlockAlloc::Alloc(), and csRedBlackTree< csRedBlackTreePayload< K, T > >::RecursiveInsert(). |
|
Allocate a block and initialize its free-node chain.
Definition at line 207 of file blockallocator.h. |
|
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 343 of file blockallocator.h. |
|
Destroy an object, optionally warning if pedanticism is desired.
Definition at line 235 of file blockallocator.h. |
|
Destroys all living objects and releases all memory allocated by the pool.
Definition at line 273 of file blockallocator.h. |
|
Destroy all objects allocated by the pool.
Definition at line 334 of file blockallocator.h. |
|
Find the memory block which contains the given memory.
Definition at line 196 of file blockallocator.h. |
|
Deallocate an object. It is safe to provide a null pointer. Definition at line 409 of file blockallocator.h. |
|
Dispose of a block.
Definition at line 227 of file blockallocator.h. |
|
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 188 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 254 of file blockallocator.h. |
|
Query number of elements per block.
Definition at line 421 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.6