Foundation
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Foundation::Core::DynamicPool< T > Class Template Reference

Mutex-protected, dynamically sized object pool with stable object pointers. More...

#include <AtomicPool.hpp>

Public Member Functions

 DynamicPool (Allocator *alloc)
 
 DynamicPool (DynamicPool const &)=delete
 
DynamicPooloperator= (DynamicPool const &)=delete
 
 DynamicPool (DynamicPool &&)=delete
 
DynamicPooloperator= (DynamicPool &&)=delete
 
template<typename... Args>
T * Construct (Args &&... args)
 Constructs an object of type T in the pool with the given arguments.
 
void Destruct (T *ptr)
 Destructs the object pointed to by ptr and releases its storage.
 
void Collect ()
 Destructs all allocated objects in the pool.
 
size_t Size () const
 
 ~DynamicPool ()
 

Private Attributes

AllocatormAllocator
 
List< TmObjects
 
Mutex mMutex
 

Detailed Description

template<typename T>
class Foundation::Core::DynamicPool< T >

Mutex-protected, dynamically sized object pool with stable object pointers.

Note
Unlike AtomicPool, this pool does not reserve a fixed arena. Each live object occupies one Core::List node and releases that node back to the allocator on destruction, so memory usage tracks the number of live objects.
Construction, destruction, and collection are thread-safe. Pointer dereference is not synchronized; callers must still avoid using handles concurrently with destruction.

Constructor & Destructor Documentation

◆ DynamicPool() [1/3]

template<typename T >
Foundation::Core::DynamicPool< T >::DynamicPool ( Allocator alloc)
inlineexplicit

◆ DynamicPool() [2/3]

template<typename T >
Foundation::Core::DynamicPool< T >::DynamicPool ( DynamicPool< T > const )
delete

◆ DynamicPool() [3/3]

template<typename T >
Foundation::Core::DynamicPool< T >::DynamicPool ( DynamicPool< T > &&  )
delete

◆ ~DynamicPool()

Member Function Documentation

◆ Collect()

template<typename T >
void Foundation::Core::DynamicPool< T >::Collect ( )
inline

Destructs all allocated objects in the pool.

◆ Construct()

template<typename T >
template<typename... Args>
T * Foundation::Core::DynamicPool< T >::Construct ( Args &&...  args)
inline

Constructs an object of type T in the pool with the given arguments.

Returns
Pointer to the constructed object.
Note
User must NOT use delete to free the returned pointer as it is managed by the pool. The destructor of T should NOT be manually called - handle both with Destruct.

◆ Destruct()

template<typename T >
void Foundation::Core::DynamicPool< T >::Destruct ( T ptr)
inline

Destructs the object pointed to by ptr and releases its storage.

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ Size()

template<typename T >
size_t Foundation::Core::DynamicPool< T >::Size ( ) const
inline

Member Data Documentation

◆ mAllocator

template<typename T >
Allocator* Foundation::Core::DynamicPool< T >::mAllocator
private

◆ mMutex

template<typename T >
Mutex Foundation::Core::DynamicPool< T >::mMutex
mutableprivate

◆ mObjects

template<typename T >
List<T> Foundation::Core::DynamicPool< T >::mObjects
private

The documentation for this class was generated from the following file: