|
OpenTTD Source
1.10.0-RC1
|
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 | IterateWrapper |
| struct | IterateWrapperFiltered |
| struct | PoolItem |
| Base class for all PoolItems. More... | |
| struct | PoolIterator |
| Iterator to iterate all valid T of a pool. More... | |
| struct | PoolIteratorFiltered |
| Iterator to iterate all valid T of a pool. More... | |
Public Member Functions | |
| assert_compile ((uint64)(Tmax_size - 1) >> 8 *sizeof(Tindex)==0) | |
| Pool (const char *name) | |
| virtual void | CleanPool () |
| Virtual method that deletes all items in the pool. | |
| Titem * | Get (size_t index) |
| Returns Titem with given index. More... | |
| bool | IsValidID (size_t index) |
| Tests whether given index can be used to get valid (non-nullptr) Titem. More... | |
| bool | CanAllocate (size_t n=1) |
| Tests whether we can allocate 'n' items. More... | |
Public Member Functions inherited from PoolBase | |
| PoolBase (PoolType pt) | |
| Constructor registers this object in the pool vector. More... | |
| virtual | ~PoolBase () |
| Destructor removes this object from the pool vector and deletes the vector itself if this was the last item removed. | |
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-nullptr) | |
| bool | cleaning |
| True if cleaning pool (deleting all items) | |
| Titem ** | data |
| Pointer to array of pointers to Titem. | |
Data Fields inherited from PoolBase | |
| const PoolType | type |
| Type of this pool. | |
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) |
| Constant to indicate we can't allocate any more items. | |
Additional Inherited Members | |
Static Public Member Functions inherited from PoolBase | |
| static PoolVector * | GetPools () |
| Function used to access the vector of all pools. More... | |
| static void | Clean (PoolType) |
| Clean all pools of given type. More... | |
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 81 of file pool_type.hpp.
|
inline |
Tests whether we can allocate 'n' items.
| n | number of items we want to allocate |
Definition at line 130 of file pool_type.hpp.
|
inline |
Returns Titem with given index.
| index | of item to get |
Definition at line 109 of file pool_type.hpp.
Referenced by Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::IsValidID().
|
inline |
Tests whether given index can be used to get valid (non-nullptr) Titem.
| index | index to examine |
Definition at line 120 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::Get().