class
cObjectPool_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
- class cObjectPool
- class cObjectPool
- class cObjectPool
- class cObjectPool
Public types
- struct Iterator
Constructors, destructors, conversion operators
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
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 |