Thread-safe object pool that reuses allocations with custom destruction.
More...
#include <spk_pool.hpp>
|
|
using | Deleter = std::function<void(TType *)> |
| | Custom deleter used to return instances to the pool.
|
|
using | Object = std::unique_ptr<TType, Deleter> |
| | Unique pointer type that recycles its payload back into the pool.
|
|
|
| Pool () |
| | Constructs an empty pool with unlimited capacity.
|
|
| ~Pool () |
| | Marks the pool as closed and prevents further allocations.
|
|
| Pool (const Pool &)=delete |
|
Pool & | operator= (const Pool &)=delete |
| void | setMaximumAllocationSize (size_t p_size) |
| | Limits the number of recyclable objects stored by the pool.
|
| size_t | size () const |
| | Retrieves the number of available objects stored in the pool.
|
| template<typename... TArgs> |
| void | allocate (TArgs &&...p_args) |
| | Pre-allocates a new instance and pushes it into the available set.
|
| template<typename... TArgs> |
| void | resize (size_t p_newSize, TArgs &&...p_args) |
| | Adjusts the pool size by constructing or discarding objects.
|
|
void | release () |
| | Clears all cached objects without closing the pool.
|
| template<typename... TArgs> |
| Object | obtain (TArgs &&...p_args) |
| | Provides an object from the pool, constructing one if necessary.
|
template<typename TType>
class spk::Pool< TType >
Thread-safe object pool that reuses allocations with custom destruction.
- Template Parameters
-
| TType | Stored object type; must be constructible with forwarded arguments. |
Thread-safe object pool that reuses allocations with custom destruction.
Definition spk_pool.hpp:29
void allocate(TArgs &&...p_args)
Pre-allocates a new instance and pushes it into the available set.
Definition spk_pool.hpp:105
Object obtain(TArgs &&...p_args)
Provides an object from the pool, constructing one if necessary.
Definition spk_pool.hpp:164
◆ allocate()
template<typename TType>
template<typename... TArgs>
| void spk::Pool< TType >::allocate |
( |
TArgs &&... | p_args | ) |
|
|
inline |
Pre-allocates a new instance and pushes it into the available set.
- Parameters
-
| p_args | Constructor arguments forwarded to TType. |
◆ obtain()
template<typename TType>
template<typename... TArgs>
Provides an object from the pool, constructing one if necessary.
- Parameters
-
| p_args | Constructor arguments forwarded to TType. |
- Returns
- Unique pointer that returns the instance to the pool on destruction.
◆ resize()
template<typename TType>
template<typename... TArgs>
| void spk::Pool< TType >::resize |
( |
size_t | p_newSize, |
|
|
TArgs &&... | p_args ) |
|
inline |
Adjusts the pool size by constructing or discarding objects.
- Parameters
-
| p_newSize | Desired number of available objects. |
| p_args | Constructor arguments forwarded to TType. |
◆ setMaximumAllocationSize()
template<typename TType>
| void spk::Pool< TType >::setMaximumAllocationSize |
( |
size_t | p_size | ) |
|
|
inline |
Limits the number of recyclable objects stored by the pool.
- Parameters
-
| p_size | Maximum number of cached instances. |
◆ size()
Retrieves the number of available objects stored in the pool.
- Returns
- Current cached object count.
The documentation for this class was generated from the following file: