![]() |
Libftpp
A modern C++ library
|
Pool of reusable memory. More...
#include <pool.hpp>
Classes | |
| class | Object |
| Wrapper around a TType object managed by the Pool. Provides access to the underlying TType object. More... | |
Public Member Functions | |
| Pool (size_t size=0) | |
| ~Pool () | |
| void | resize (size_t numberOfObjectStored) |
| Pre-allocates memory for a given number of objects. More... | |
| template<typename... TArgs> | |
| Object & | acquire (TArgs &&... p_args) |
| Acquires an object from the pool. More... | |
| void | release (Object &obj) |
| Releases an object back into the pool. Destroys the contained TType object and return its slot to the available Stack. More... | |
Pool of reusable memory.
RAII is used to manage the lifetime of objects.
The Pool pre-allocates objects of type TType and reuses them to avoid frequent allocations and deallocations.
| TType | Type of objects managed by the pool. |
| Object& Pool< TType >::acquire | ( | TArgs &&... | p_args | ) |
Acquires an object from the pool.
Constructs a new TType object in pre-allocated memory and returns a wrapper Object to access it.
| TArgs | Types of constructor arguments for TType. |
| p_args | Arguments forwarded to TType's constructor. |
| std::out_of_range | if no objects are available in the pool. |
Releases an object back into the pool. Destroys the contained TType object and return its slot to the available Stack.
| void Pool< TType >::resize | ( | size_t | numberOfObjectStored | ) |
Pre-allocates memory for a given number of objects.
| numberOfObjectStored | Number of objects to pre-allocate. |