Cogs.Core
|
Base class for data pools. More...
#include <ComponentDataPool.h>
Public Member Functions | |
COGSFOUNDATION_API | ComponentDataPoolBase (SizeType capacity, size_t elementSize, MemBlockType memType=MemBlockType::Bucket) |
Constructs a data pool with the given capacity and element size. | |
COGSFOUNDATION_API void | allocate (ComponentHandle handle) |
Allocate a new data element in the pool at the index used by the given component handle. | |
COGSFOUNDATION_API void | deallocate (ComponentHandle handle) |
Deallocate the data element in the pool at the index used by the given component handle. | |
void * | operator[] (SizeType index) |
Retrieve a pointer to the data for the element at the given index. | |
const void * | operator[] (SizeType index) const |
Retrieve a const pointer to the data for the element at the given index. | |
Base class for data pools.
The data pool can hold a number of elements of a specified size. The elements can be allocated, retrieved, or deallocated using element indexes.
When indexes outside of the currently allocated storage are given, the pool will grow automatically.
NOTE: Storing self-referential types in the pool is not supported and will break when resizing the pool, since there is no guarantee the storage will have the same physical address.
Definition at line 23 of file ComponentDataPool.h.
Cogs::ComponentModel::ComponentDataPoolBase::ComponentDataPoolBase | ( | SizeType | capacity, |
size_t | elementSize, | ||
MemBlockType | memType = MemBlockType::Bucket |
||
) |
Constructs a data pool with the given capacity and element size.
capacity | Number of elements to allocate storage for in the pool. |
elementSize | Size of individual elements in the pool, given in bytes. |
Definition at line 7 of file ComponentDataPool.cpp.
void Cogs::ComponentModel::ComponentDataPoolBase::allocate | ( | ComponentHandle | handle | ) |
Allocate a new data element in the pool at the index used by the given component handle.
If the index of the handle is equal to or outside the current capacity, the pool will grow to accommodate the given index.
Currently, the pool will grow by a factor of approximately 1.5 when needed.
Definition at line 13 of file ComponentDataPool.cpp.
Referenced by Cogs::ComponentModel::ComponentDataPool< DataType >::create().
void Cogs::ComponentModel::ComponentDataPoolBase::deallocate | ( | ComponentHandle | handle | ) |
Deallocate the data element in the pool at the index used by the given component handle.
Definition at line 29 of file ComponentDataPool.cpp.
Referenced by Cogs::ComponentModel::ComponentDataPool< DataType >::destroy().
|
inline |
Retrieve a pointer to the data for the element at the given index.
Definition at line 48 of file ComponentDataPool.h.
Referenced by Cogs::ComponentModel::ComponentDataPool< DataType >::create(), Cogs::ComponentModel::ComponentDataPool< DataType >::destroy(), and Cogs::ComponentModel::ComponentDataPool< DataType >::operator[]().
|
inline |
Retrieve a const pointer to the data for the element at the given index.
Definition at line 57 of file ComponentDataPool.h.