Stores objects of any type with size upto sizeof(std::size_t) * 64 Bytes in contiguous aligned memory.
More...
#include <ObjectPool.hpp>
|
| template<typename T > |
| Handle | push (T &&object) |
| | Pushes an object of type T into the ObjectPool. More...
|
| |
| template<typename T , typename... Args> |
| Handle | emplace (Args...args) |
| | In-place constructs an object of type T into the ObjectPool. More...
|
| |
| template<typename T > |
| T * | get (const Handle &handle) |
| | Gets a pointer to an object in the ObjectPool. More...
|
| |
| template<typename T > |
| void | erase (const Handle &handle) |
| | Removes an object from the ObjectPool and free's the space for reuse. More...
|
| |
| template<typename T > |
| auto | makeUnique (const Handle &h) |
| | Creates a unique pointer for automatic lifetime tracking of an already allocated object. More...
|
| |
| template<typename T > |
| auto | makeShared (const Handle &h) |
| | Creates a shared pointer for automatic lifetime tracking of an already allocated object. More...
|
| |
| void | defragment () |
| | Defragments the ObjectPool such that objects located after the first free position are moved to earlier free positions. More...
|
| |
| void | shrink () |
| | Deletes unused pages from Pools. More...
|
| |
| std::size_t | capacity () |
| | Returns the currently used memory (in bytes) in total for all the Pools. More...
|
| |
| template<typename T > |
| std::size_t | capacity () |
| | Returns the currently used memory (in bytes) for the Pool that fits sizeof(T). More...
|
| |
Stores objects of any type with size upto sizeof(std::size_t) * 64 Bytes in contiguous aligned memory.
For more information and examples, see page ObjectPool.
| std::size_t rz::objectpool::ObjectPool::capacity |
( |
| ) |
|
|
inline |
Returns the currently used memory (in bytes) in total for all the Pools.
template<typename T >
| std::size_t rz::objectpool::ObjectPool::capacity |
( |
| ) |
|
|
inline |
Returns the currently used memory (in bytes) for the Pool that fits sizeof(T).
| void rz::objectpool::ObjectPool::defragment |
( |
| ) |
|
|
inline |
Defragments the ObjectPool such that objects located after the first free position are moved to earlier free positions.
Note: Potentialy invalidates pointers but does not invalidate Handles.
template<typename T , typename... Args>
| Handle rz::objectpool::ObjectPool::emplace |
( |
Args... |
args | ) |
|
|
inline |
In-place constructs an object of type T into the ObjectPool.
- Template Parameters
-
| T | The type of the object to be constructed in the ObjectPool. |
| Args | The parameter pack used to construct the T object.[1] |
- Parameters
-
| args | Constructor arguments to pass to the constructor of T. |
- Return values
-
[1] Don't enter this. It deduced by the compiler.
template<typename T >
| void rz::objectpool::ObjectPool::erase |
( |
const Handle & |
handle | ) |
|
|
inline |
Removes an object from the ObjectPool and free's the space for reuse.
It calls the destructor for non-trivially destructible objects.
- Template Parameters
-
| T | The type of the object to remove from the ObjectPool. |
- Parameters
-
template<typename T >
| T * rz::objectpool::ObjectPool::get |
( |
const Handle & |
handle | ) |
|
|
inline |
Gets a pointer to an object in the ObjectPool.
- Template Parameters
-
| T | The type of the object to get from the ObjectPool. |
- Parameters
-
- Exceptions
-
| std::invalid_argument | T and handle are mismatched. |
- Return values
-
| T* | On success, a pointer to the desired object. |
| nullptr | On failure, a nullptr. |
template<typename T >
| auto rz::objectpool::ObjectPool::makeShared |
( |
const Handle & |
h | ) |
|
Creates a shared pointer for automatic lifetime tracking of an already allocated object.
Note: Destroying or reasigning the last shared pointer will call ObjectPool::erase with the appropriate destructor. Also, manually calling ObjectPool::erase will invalidate the pointers.
- Template Parameters
-
| T | The type of the object to create a shared pointer for. |
- Parameters
-
| Handle | The Handle of the object to create a shared pointer for. |
- Returns
- std::shared_ptr<Handle> A shared pointer to the object in the ObjectPool.
template<typename T >
| auto rz::objectpool::ObjectPool::makeUnique |
( |
const Handle & |
h | ) |
|
Creates a unique pointer for automatic lifetime tracking of an already allocated object.
Note: Destroying or reasigning the unique pointer will call ObjectPool::erase with the appropriate destructor. Also, manually calling ObjectPool::erase will invalidate the pointer.
- Template Parameters
-
| T | The type of the object to create a unique pointer for. |
- Parameters
-
| Handle | The Handle of the object to create a unique pointer for. |
- Returns
- std::unique_ptr<Handle> A unique pointer to the object in the ObjectPool.
template<typename T >
| Handle rz::objectpool::ObjectPool::push |
( |
T && |
object | ) |
|
|
inline |
Pushes an object of type T into the ObjectPool.
- Template Parameters
-
| T | The type of the object to be moved into the ObjectPool.[1] |
- Parameters
-
- Returns
- Handle A Handle for accessing the object.
[1] Don't enter this. It deduced by the compiler.
| void rz::objectpool::ObjectPool::shrink |
( |
| ) |
|
|
inline |
Deletes unused pages from Pools.
The documentation for this class was generated from the following file: