← API Reference Class

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.

Template Parameters
T

Element type stored in each pool slot.

N

Number of slots; fixed at compile time.

Public Types

#using size_type = std::size_t
#using slot_type = Slot
#using value_type = T
#using pointer = std::unique_ptr< T, Deleter >

Private Attributes

#std::array< Slot, N > m_Poolprivate
#Slot * m_FreeHead {nullptr}private
#std::size_t m_Used {0}private

Private Member Functions

#PoolAllocator()private
#void Free(T *inPtr) noexceptprivate

Returns a slot to the free-list and destructs the held object.

Note

Called exclusively by Deleter — not part of the public API.

Public Member Functions

#PoolAllocator(const PoolAllocator &)=delete
#PoolAllocator & operator=(const PoolAllocator &)=delete
#PoolAllocator(PoolAllocator &&)=delete
#PoolAllocator & operator=(PoolAllocator &&)=delete
#template<typename ... _Args> pointer Alloc(_Args &&...inArgs) noexcept

Constructs 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.

Template Parameters
_Args

Constructor argument types for T.

Parameters
inArgs

Arguments forwarded to T's constructor.

Returns

An owning pointer to the constructed object, or nullptr.

#size_type Used() const noexcept
#size_type Remaining() const noexcept
#size_type Full() const noexcept
#size_type Empty() const noexcept

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.

Returns

A shared_ptr owning the new pool.