Cogs.Core
Public Member Functions | List of all members
Cogs::ComponentModel::ComponentDataPoolBase Class Reference

Base class for data pools. More...

#include <ComponentDataPool.h>

Inheritance diagram for Cogs::ComponentModel::ComponentDataPoolBase:
Cogs::ComponentModel::ComponentDataPool< DataType >

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ComponentDataPoolBase()

Cogs::ComponentModel::ComponentDataPoolBase::ComponentDataPoolBase ( SizeType  capacity,
size_t  elementSize,
MemBlockType  memType = MemBlockType::Bucket 
)

Constructs a data pool with the given capacity and element size.

Parameters
capacityNumber of elements to allocate storage for in the pool.
elementSizeSize of individual elements in the pool, given in bytes.

Definition at line 7 of file ComponentDataPool.cpp.

Member Function Documentation

◆ allocate()

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

◆ deallocate()

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

◆ operator[]() [1/2]

void * Cogs::ComponentModel::ComponentDataPoolBase::operator[] ( SizeType  index)
inline

◆ operator[]() [2/2]

const void * Cogs::ComponentModel::ComponentDataPoolBase::operator[] ( SizeType  index) const
inline

Retrieve a const pointer to the data for the element at the given index.

Definition at line 57 of file ComponentDataPool.h.


The documentation for this class was generated from the following files: