Simulator::cObjectPool_ class

Stores a pool of objects whose memory can be reused efficiently, without need for heap allocations.

Objects within the pool are identifier with a cObjectPoolIndex. All objects must be subclasses of cObjectPoolClass

Iteration example:

cObjectPool pool;
// ...
cObjectPool::Iterator it;
cObjectPoolClass* object;
while ((object = pool.Iterate(it)) != nullptr) {
    
}

Derived classes

template<typename T>
class cObjectPool
template<typename T>
class cObjectPool
template<typename T>
class cObjectPool
template<typename T>
class cObjectPool

Public types

struct Iterator

Constructors, destructors, conversion operators

cObjectPool_()
~cObjectPool_()

Public functions

auto Initialize(int objectSize, int numObjects) -> void
auto Clear() -> void
Removes all objects.
auto Get(cObjectPoolIndex index) -> cObjectPoolClass*
Returns the object at the given index.
auto GetIfNotDeleted(cObjectPoolIndex index) -> cObjectPoolClass*
Returns the object at the given index, only if it has not been deleted.
auto CreateObject() -> cObjectPoolIndex
Creates a new object in the pool, with all memory set to 0 except for the identifying index.
auto DeleteObject(cObjectPoolIndex index) -> void
auto Iterate(Iterator& it) const -> cObjectPoolClass*
Advances the iterator and returns the next object, or nullptr if the iterator reached the end.

Public variables

void* mpData
int mNextAvailableIndex
int mObjectPoolIndentifier
int mNumObjects
int mNumAllocatedObjects
int mObjectSize
int field_18

Function documentation

cObjectPoolClass* Simulator::cObjectPool_::Get(cObjectPoolIndex index)

Returns the object at the given index.

Parameters
index

This will return even if the index is not valid or the object is not alive.

cObjectPoolClass* Simulator::cObjectPool_::GetIfNotDeleted(cObjectPoolIndex index)

Returns the object at the given index, only if it has not been deleted.

Parameters
index
Returns The object, or nullptr if the object was deleted.

cObjectPoolIndex Simulator::cObjectPool_::CreateObject()

Creates a new object in the pool, with all memory set to 0 except for the identifying index.

Returns The index used to access the new object.

cObjectPoolClass* Simulator::cObjectPool_::Iterate(Iterator& it) const

Advances the iterator and returns the next object, or nullptr if the iterator reached the end.

Parameters
it @eturns