Data Structures | Public Member Functions | Data Fields | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes

# Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero > Struct Template Reference

Base class for all pools. More...

`#include <pool_type.hpp>`

Inheritance diagram for Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >:

## 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.

## Detailed Description

### template<class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >

Base class for all pools.

Template Parameters:

  | 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

Warning:
  when Tcache is enabled *all* instances of this pool's item must be of the same size.

Definition at line 76 of file pool_type.hpp.

## Member Function Documentation

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>

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.

Parameters:

  | n | number of items we want to allocate

Returns:
  true if 'n' items can be allocated

Definition at line 122 of file pool_type.hpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::items.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>

Titem* Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::Get | ( | size_t | index | ) | `[inline]`

Returs Titem with given index.

Parameters:

  | index | of item to get

Returns:
  pointer to Titem

Precondition:
  index < this->first_unused

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().

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>

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.

Parameters:

  | index | index to examine

Returns:
  true if PoolItem::Get(index) will return non-NULL pointer

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().

The documentation for this struct was generated from the following file:

- src/core/pool_type.hpp