![]() |
Deluge Firmware 1.3.0
Build date: 2025.04.16
|
A simple object pool implementation. More...
#include <object_pool.h>
Public Types | |
using | value_type = T |
The type of object in the pool. | |
using | pointer_type = std::unique_ptr<T, decltype(&recycle)> |
A managed pointer type for an object from the pool. | |
Public Member Functions | |
void | resize (size_t n) |
Sets the size of the pool. | |
size_t | capacity () const |
Gets the capacity of the pool. | |
size_t | size () const |
Gets the number of objects in the pool. | |
void | repopulate () noexcept(false) |
Repopulates the pool to its original size. | |
template<typename... Args> | |
pointer_type | acquire (Args &&... args) noexcept(false) |
Acquires an object from the pool. | |
void | clear () |
Clears the pool. | |
constexpr bool | empty () const |
Checks if the pool is empty. | |
Static Public Member Functions | |
static constexpr ObjectPool & | get () |
Gets the global pool for a given object. | |
static void | recycle (gsl::owner< T * > obj) |
Private Attributes | |
size_t | capacity_ = kDefaultSize |
std::stack< T *, std::vector< T *, Alloc< T * > > > | objects_ |
Alloc< T > | alloc_ |
Static Private Attributes | |
static constexpr size_t | kDefaultSize = 48 |
A simple object pool implementation.
T | The type of object to pool |
Alloc | The allocator to use for the pool |
|
inlinenodiscard |
Acquires an object from the pool.
Args | The types of arguments to pass to the object's constructor |
args | The arguments to pass to the object's constructor |
deluge::exception::BAD_ALLOC | if memory allocation fails |
|
inlinenodiscard |
Gets the capacity of the pool.
|
inlinenodiscardconstexpr |
Checks if the pool is empty.
|
inlinestaticconstexpr |
Gets the global pool for a given object.
|
inlinestatic |
Recycles an object back into the pool
obj | The object to recycle |
|
inline |
Repopulates the pool to its original size.
deluge::exception::BAD_ALLOC | if memory allocation fails |
|
inline |
Sets the size of the pool.
size | The new size of the pool |
|
inlinenodiscard |
Gets the number of objects in the pool.