|
DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
|
Generic object pool: caches unique_ptr<T> instances and hands them out with RAII return-on-destruction semantics.
More...
#include <ObjectPool.hpp>
Classes | |
| class | ObjectPoolAllocated |
| RAII handle returned by ObjectPoolget (and friends). More... | |
| struct | Pool |
| Internal storage shared among all handles. More... | |
Public Types | |
| using | uPtrResource = std::unique_ptr< T > |
Public Member Functions | |
| ObjectPool () | |
| Construct an empty pool; populate with resize. | |
| size_t | size () |
| Number of objects currently available (not checked out). | |
| template<class... _CtorArgs> | |
| void | resize (size_t N, _CtorArgs &&...__ctorArgs) |
Pre-allocate N objects, forwarding __ctorArgs to each ctor. Clears any previously pooled instances. | |
| template<class TFInit , class... _CtorArgs> | |
| void | resizeInit (size_t N, TFInit &&FInit, _CtorArgs &&...__ctorArgs) |
Like resize but calls FInit(obj) on each newly-created object. | |
| ObjectPoolAllocated | get () |
| Take an object out of the pool. Returns an empty handle if exhausted. | |
| template<class... _CtorArgs> | |
| ObjectPoolAllocated | getAlloc (_CtorArgs &&...__ctorArgs) |
| Like get, but allocates a brand-new object if the pool is empty. | |
| template<class TFInit , class... _CtorArgs> | |
| ObjectPoolAllocated | getAllocInit (TFInit &&FInit, _CtorArgs &&...__ctorArgs) |
Like getAlloc, but additionally runs FInit(obj) on newly-allocated objects. | |
Public Attributes | |
| std::shared_ptr< Pool > | pPool |
| Shared pointer to the underlying storage. | |
Generic object pool: caches unique_ptr<T> instances and hands them out with RAII return-on-destruction semantics.
Intended for expensive-to-construct objects used in hot loops (e.g., Eigen solvers, pre-allocated scratch matrices). Typical pattern:
The pool shares ownership with every outstanding ObjectPoolAllocated via a shared_ptr<Pool>; workers correctly skip the return step if the pool itself has been destroyed meanwhile.
| T | Pooled object type. |
Definition at line 32 of file ObjectPool.hpp.
| using DNDS::ObjectPool< T >::uPtrResource = std::unique_ptr<T> |
Definition at line 35 of file ObjectPool.hpp.
|
inline |
Construct an empty pool; populate with resize.
Definition at line 51 of file ObjectPool.hpp.
|
inline |
Take an object out of the pool. Returns an empty handle if exhausted.
Definition at line 135 of file ObjectPool.hpp.
|
inline |
Like get, but allocates a brand-new object if the pool is empty.
Definition at line 148 of file ObjectPool.hpp.
|
inline |
Like getAlloc, but additionally runs FInit(obj) on newly-allocated objects.
Definition at line 162 of file ObjectPool.hpp.
|
inline |
Pre-allocate N objects, forwarding __ctorArgs to each ctor. Clears any previously pooled instances.
Definition at line 109 of file ObjectPool.hpp.
|
inline |
Like resize but calls FInit(obj) on each newly-created object.
Definition at line 122 of file ObjectPool.hpp.
|
inline |
Number of objects currently available (not checked out).
Definition at line 57 of file ObjectPool.hpp.
| std::shared_ptr<Pool> DNDS::ObjectPool< T >::pPool |
Shared pointer to the underlying storage.
Definition at line 47 of file ObjectPool.hpp.