Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::mem::StackAllocator Class Referencefinal

PMR stack allocator with LIFO-aware deallocation. More...

#include <stack_allocator.hpp>

Inheritance diagram for helios::mem::StackAllocator:

Classes

struct  Marker
 Marker for rewind operations. More...

Public Member Functions

 StackAllocator (StackAllocatorOptions options) noexcept
 Constructs stack allocator from options.
 StackAllocator (size_t initial_capacity) noexcept
 Constructs stack allocator with geometric growth.
 StackAllocator (const StackAllocator &)=delete
 StackAllocator (StackAllocator &&other) noexcept
 Move-constructs stack allocator from another instance.
 ~StackAllocator () noexcept override
StackAllocatoroperator= (const StackAllocator &)=delete
StackAllocatoroperator= (StackAllocator &&other) noexcept
 Move-assigns stack state from another instance.
void RewindToMarker (Marker marker) noexcept
 Rewinds allocator to marker.
void Reset () noexcept
 Resets allocator to a fresh single initial block.
bool Empty () const noexcept
 Returns true when no active allocations remain.
Marker GetMarker () const noexcept
 Returns current marker.
AllocatorStats Stats () const noexcept
 Returns runtime statistics.
size_t InitialCapacity () const noexcept
 Returns initial block capacity.
size_t TotalCapacity () const noexcept
 Returns total capacity across block chain.
size_t BlockCount () const noexcept
 Returns current number of blocks.
GrowthPolicy Growth () const noexcept
 Returns growth policy.

Detailed Description

PMR stack allocator with LIFO-aware deallocation.

Uses block-chained bump allocation with per-allocation headers.

Allocation path is lock-free with atomic CAS on head block offset. Deallocate tries LIFO rewind when possible. Non-LIFO deallocation is treated as no-op, which keeps PMR compatibility for containers that may free out of order.

Note
allocate and LIFO deallocate on the current head are lock-free. Reset, GetMarker, and RewindToMarker require external synchronization. Marker.block is internal and invalid after growth.

Definition at line 35 of file stack_allocator.hpp.

Constructor & Destructor Documentation

◆ StackAllocator() [1/4]

helios::mem::StackAllocator::StackAllocator ( StackAllocatorOptions options)
inlineexplicitnoexcept

Constructs stack allocator from options.

Warning
Triggers assertion if options.initial_capacity == 0 or options.growth.max_capacity < options.initial_capacity.
Parameters
optionsStack allocator options

Definition at line 203 of file stack_allocator.hpp.

◆ StackAllocator() [2/4]

helios::mem::StackAllocator::StackAllocator ( size_t initial_capacity)
inlineexplicitnoexcept

Constructs stack allocator with geometric growth.

Warning
Triggers assertion if initial_capacity == 0.
Parameters
initial_capacityInitial block capacity

Definition at line 58 of file stack_allocator.hpp.

◆ StackAllocator() [3/4]

helios::mem::StackAllocator::StackAllocator ( const StackAllocator & )
delete

◆ StackAllocator() [4/4]

helios::mem::StackAllocator::StackAllocator ( StackAllocator && other)
inlinenoexcept

Move-constructs stack allocator from another instance.

Parameters
otherSource allocator; left in empty moved-from state

Definition at line 69 of file stack_allocator.hpp.

◆ ~StackAllocator()

helios::mem::StackAllocator::~StackAllocator ( )
inlineoverridenoexcept

Definition at line 70 of file stack_allocator.hpp.

Member Function Documentation

◆ BlockCount()

size_t helios::mem::StackAllocator::BlockCount ( ) const
inlinenodiscardnoexcept

Returns current number of blocks.

Returns
Block count

Definition at line 137 of file stack_allocator.hpp.

◆ Empty()

bool helios::mem::StackAllocator::Empty ( ) const
inlinenodiscardnoexcept

Returns true when no active allocations remain.

Returns
True if empty, false otherwise.

Definition at line 101 of file stack_allocator.hpp.

◆ GetMarker()

auto helios::mem::StackAllocator::GetMarker ( ) const
inlinenodiscardnoexcept

Returns current marker.

Returns
Marker that can later be rewound to

Definition at line 229 of file stack_allocator.hpp.

◆ Growth()

GrowthPolicy helios::mem::StackAllocator::Growth ( ) const
inlinenodiscardnoexcept

Returns growth policy.

Returns
Growth policy

Definition at line 145 of file stack_allocator.hpp.

◆ InitialCapacity()

size_t helios::mem::StackAllocator::InitialCapacity ( ) const
inlinenodiscardnoexcept

Returns initial block capacity.

Returns
Capacity in bytes

Definition at line 121 of file stack_allocator.hpp.

◆ operator=() [1/2]

StackAllocator & helios::mem::StackAllocator::operator= ( const StackAllocator & )
delete

◆ operator=() [2/2]

StackAllocator & helios::mem::StackAllocator::operator= ( StackAllocator && other)
inlinenoexcept

Move-assigns stack state from another instance.

Parameters
otherSource allocator; left in empty moved-from state
Returns
Reference to this allocator

Definition at line 218 of file stack_allocator.hpp.

◆ Reset()

void helios::mem::StackAllocator::Reset ( )
noexcept

Resets allocator to a fresh single initial block.

Warning
Must not be called concurrently with allocation/deallocation.

Definition at line 20 of file stack_allocator.cpp.

◆ RewindToMarker()

void helios::mem::StackAllocator::RewindToMarker ( Marker marker)
noexcept

Rewinds allocator to marker.

Warning
Must not be called concurrently with allocation/deallocation. Triggers assertion if marker does not belong to this allocator.
Parameters
markerMarker previously returned by GetMarker

Definition at line 42 of file stack_allocator.cpp.

◆ Stats()

AllocatorStats helios::mem::StackAllocator::Stats ( ) const
inlinenodiscardnoexcept

Returns runtime statistics.

Returns
Allocator stats snapshot

Definition at line 241 of file stack_allocator.hpp.

◆ TotalCapacity()

size_t helios::mem::StackAllocator::TotalCapacity ( ) const
inlinenodiscardnoexcept

Returns total capacity across block chain.

Returns
Capacity in bytes

Definition at line 129 of file stack_allocator.hpp.