Base class for all pools. More...
#include <pool_type.hpp>
Data Structures | |
struct | AllocCache |
Helper struct to cache 'freed' PoolItems so we do not need to allocate them again. More... | |
struct | PoolItem |
Base class for all PoolItems. More... | |
Public Member Functions | |
Pool (const char *name) | |
virtual void | CleanPool () |
Virtual method that deletes all items in the pool. | |
Titem * | Get (size_t index) |
Returs Titem with given index. | |
bool | IsValidID (size_t index) |
Tests whether given index can be used to get valid (non-NULL) Titem. | |
bool | CanAllocate (size_t n=1) |
Tests whether we can allocate 'n' items. | |
Data Fields | |
const char *const | name |
Name of this pool. | |
size_t | size |
Current allocated size. | |
size_t | first_free |
No item with index lower than this is free (doesn't say anything about this one!). | |
size_t | first_unused |
This and all higher indexes are free (doesn't say anything about first_unused-1 !). | |
size_t | items |
Number of used indexes (non-NULL). | |
bool | cleaning |
True if cleaning pool (deleting all items). | |
Titem ** | data |
Pointer to array of pointers to Titem. | |
Static Public Attributes | |
static const size_t | MAX_SIZE = Tmax_size |
Make template parameter accessible from outside. | |
Private Member Functions | |
void * | AllocateItem (size_t size, size_t index) |
void | ResizeFor (size_t index) |
size_t | FindFirstFree () |
void * | GetNew (size_t size) |
void * | GetNew (size_t size, size_t index) |
void | FreeItem (size_t index) |
Private Attributes | |
AllocCache * | alloc_cache |
Cache of freed pointers. | |
Static Private Attributes | |
static const size_t | NO_FREE_ITEM = MAX_UVALUE(size_t) |
Contant to indicate we can't allocate any more items. |
Base class for all pools.
Titem | Type of the class/struct that is going to be pooled | |
Tindex | Type of the index for this pool | |
Tgrowth_step | Size of growths; if the pool is full increase the size by this amount | |
Tmax_size | Maximum size of the pool | |
Tpool_type | Type of this pool | |
Tcache | Whether to perform 'alloc' caching, i.e. don't actually free/malloc just reuse the memory | |
Tzero | Whether to zero the memory |
Definition at line 76 of file pool_type.hpp.
bool Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::CanAllocate | ( | size_t | n = 1 |
) | [inline] |
Tests whether we can allocate 'n' items.
n | number of items we want to allocate |
Definition at line 122 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::items.
Titem* Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::Get | ( | size_t | index | ) | [inline] |
Returs Titem with given index.
index | of item to get |
Definition at line 101 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::data, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::first_unused.
Referenced by Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::IsValidID().
bool Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::IsValidID | ( | size_t | index | ) | [inline] |
Tests whether given index can be used to get valid (non-NULL) Titem.
index | index to examine |
Definition at line 112 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::first_unused, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::Get().