template<typename T, std::size_t N> asge::mem::PoolAllocator
Fixed-capacity pool allocator backed by stack storage.
#include <PoolAllocator.hpp>Inherits from std::enable_shared_from_this< PoolAllocator< T, N > >.
Inheritance
classDiagram
class N1["asge::mem::PoolAllocator"]
class N2["std::enable_shared_from_this"]
N2 <|-- N1
click N1 href "classasge_1_1mem_1_1PoolAllocator.html"
Collaboration
classDiagram
class N1["asge::mem::PoolAllocator"]
class N2["std::enable_shared_from_this"]
N2 <|-- N1
click N1 href "classasge_1_1mem_1_1PoolAllocator.html"
Manages a static array of N slots, each sized and aligned for T. Slots are linked in a free-list; allocation and deallocation are both O(1).
Ownership is expressed through a pointer (a std::unique_ptr with a custom deleter). When a pointer is destroyed the slot is automatically returned to the pool and the object's destructor is called.
The allocator must be created via Create() so that its lifetime is managed by a shared_ptr. The deleter of each live pointer holds a shared_ptr back to the pool, ensuring the pool outlives all of its outstanding allocations even if the caller drops their own shared_ptr.
Copy and move are disabled — the internal slot addresses must remain stable.
T | Element type stored in each pool slot. |
N | Number of slots; fixed at compile time. |
Public Types
using size_type = std::size_tusing slot_type = Slotusing value_type = Tusing pointer = std::unique_ptr< T, Deleter >Private Attributes
Private Member Functions
Returns a slot to the free-list and destructs the held object.
Called exclusively by Deleter — not part of the public API.
Public Member Functions
PoolAllocator(const PoolAllocator &)=deletePoolAllocator & operator=(const PoolAllocator &)=deletePoolAllocator(PoolAllocator &&)=deletePoolAllocator & operator=(PoolAllocator &&)=deleteConstructs a T in the next free slot and returns an owning handle.
Returns a null pointer when the pool is exhausted (all N slots are in use). The returned pointer's deleter keeps the pool alive independently of the caller's shared_ptr.
_Args | Constructor argument types for |
inArgs | Arguments forwarded to |
An owning pointer to the constructed object, or nullptr.
Static Public Member Functions
static std::shared_ptr< PoolAllocator > Create()Creates a pool allocator managed by a shared_ptr.
The constructor is private; this factory is the only way to obtain an instance so that shared_from_this works correctly.
A shared_ptr owning the new pool.