CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

csBlockAllocator Class Template Reference

This class implements a memory allocator which can efficiently allocate objects that all have the same size. More...

#include <blockallocator.h>

List of all members.

Public Methods

 csBlockAllocator (int s)
 Construct a new block allocator which uses 'size' elements per block. More...

 ~csBlockAllocator ()
 Destruct all. More...

T * Alloc ()
 Allocate a new element. More...

void Free (T *el)
 Deallocate an element. More...

void Dump ()
 For debugging: dump contents. More...


Detailed Description

template<class T>
class csBlockAllocator< T >

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 8 bytes) and is extremely fast, both for Alloc and Free. Only restriction is it can only be used for the same type of object.

Note that the objects are properly constructed and destructed.

WARNING: This class does VERY little error checking!

Definition at line 42 of file blockallocator.h.


Constructor & Destructor Documentation

template<class T>
csBlockAllocator< T >::csBlockAllocator int    s [inline]
 

Construct a new block allocator which uses 'size' elements per block.

Using a bigger 'size' means there is more memory 'wasted' but it makes performance faster.

Definition at line 116 of file blockallocator.h.

References csArray::Push.

template<class T>
csBlockAllocator< T >::~csBlockAllocator   [inline]
 

Destruct all.

Note that objects have to be freed properly before the block allocator is called, otherwise the destructors will not be called! In debug mode this destructor will also check that all objects are freed correctly.

Definition at line 139 of file blockallocator.h.

References csArray::Length.


Member Function Documentation

template<class T>
T* csBlockAllocator< T >::Alloc   [inline]
 

Allocate a new element.

Definition at line 156 of file blockallocator.h.

template<class T>
void csBlockAllocator< T >::Dump   [inline]
 

For debugging: dump contents.

Definition at line 308 of file blockallocator.h.

References csArray::Length.

template<class T>
void csBlockAllocator< T >::Free T *    el [inline]
 

Deallocate an element.

It is ok to give a NULL pointer here.

Definition at line 187 of file blockallocator.h.


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.2.14