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

PMR stack allocator with fixed runtime capacity. More...

#include <fixed_stack_allocator.hpp>

Inheritance diagram for helios::mem::FixedStackAllocator:

Classes

struct  Marker
 Marker capturing the current bump offset for rewind operations. More...

Public Member Functions

 FixedStackAllocator (size_t capacity) noexcept
 Constructs fixed stack with the given backing capacity.
 FixedStackAllocator (const FixedStackAllocator &)=delete
 FixedStackAllocator (FixedStackAllocator &&other) noexcept
 Move-constructs fixed stack from another instance.
 ~FixedStackAllocator () noexcept override
FixedStackAllocatoroperator= (const FixedStackAllocator &)=delete
FixedStackAllocatoroperator= (FixedStackAllocator &&other) noexcept
 Move-assigns fixed stack state from another instance.
void RewindToMarker (Marker marker) noexcept
 Rewinds bump offset to marker.
void Reset () noexcept
 Soft-resets bump offset and statistics.
bool Empty () const noexcept
 Returns true when no active allocations remain.
bool Owns (const void *ptr) const noexcept
 Checks whether pointer belongs to this stack's backing buffer.
Marker GetMarker () const noexcept
 Returns current marker.
AllocatorStats Stats () const noexcept
 Returns runtime statistics snapshot.
size_t InitialCapacity () const noexcept
 Returns configured backing capacity.
size_t TotalCapacity () const noexcept
 Returns configured backing capacity.

Detailed Description

PMR stack allocator with fixed runtime capacity.

LIFO-aware deallocation on the current top allocation uses CAS on the bump offset. Non-LIFO frees are no-ops for PMR compatibility.

Note
allocate and LIFO deallocate on the current head are lock-free.
Warning
Reset() and RewindToMarker() must not run concurrently with allocate or deallocate.

Definition at line 22 of file fixed_stack_allocator.hpp.

Constructor & Destructor Documentation

◆ FixedStackAllocator() [1/3]

helios::mem::FixedStackAllocator::FixedStackAllocator ( size_t capacity)
inlineexplicitnoexcept

Constructs fixed stack with the given backing capacity.

Warning
Triggers assertion if capacity is too small. Triggers verification failure if backing allocation fails.
Parameters
capacityBacking buffer size in bytes

Definition at line 138 of file fixed_stack_allocator.hpp.

◆ FixedStackAllocator() [2/3]

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

◆ FixedStackAllocator() [3/3]

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

Move-constructs fixed stack from another instance.

Parameters
otherSource allocator; left in empty moved-from state

Definition at line 43 of file fixed_stack_allocator.hpp.

◆ ~FixedStackAllocator()

helios::mem::FixedStackAllocator::~FixedStackAllocator ( )
inlineoverridenoexcept

Definition at line 44 of file fixed_stack_allocator.hpp.

Member Function Documentation

◆ Empty()

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

Returns true when no active allocations remain.

Returns
True if empty, false otherwise

Definition at line 73 of file fixed_stack_allocator.hpp.

◆ GetMarker()

Marker helios::mem::FixedStackAllocator::GetMarker ( ) const
inlinenodiscardnoexcept

Returns current marker.

Returns
Marker that can later be rewound to

Definition at line 88 of file fixed_stack_allocator.hpp.

◆ InitialCapacity()

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

Returns configured backing capacity.

Returns
Capacity in bytes

Definition at line 102 of file fixed_stack_allocator.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Move-assigns fixed stack state from another instance.

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

Definition at line 148 of file fixed_stack_allocator.hpp.

◆ Owns()

bool helios::mem::FixedStackAllocator::Owns ( const void * ptr) const
inlinenodiscardnoexcept

Checks whether pointer belongs to this stack's backing buffer.

Parameters
ptrPointer to test
Returns
True when owned, false otherwise

Definition at line 175 of file fixed_stack_allocator.hpp.

◆ Reset()

void helios::mem::FixedStackAllocator::Reset ( )
inlinenoexcept

Soft-resets bump offset and statistics.

Warning
Must not be called concurrently with allocate or deallocate.

Definition at line 170 of file fixed_stack_allocator.hpp.

◆ RewindToMarker()

void helios::mem::FixedStackAllocator::RewindToMarker ( Marker marker)
inlinenoexcept

Rewinds bump offset to marker.

Warning
Must not be called concurrently with allocate or deallocate. Triggers assertion when marker.offset exceeds the current offset.
Parameters
markerMarker previously returned by GetMarker

Definition at line 159 of file fixed_stack_allocator.hpp.

◆ Stats()

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

Returns runtime statistics snapshot.

Returns
Allocator stats for this stack

Definition at line 187 of file fixed_stack_allocator.hpp.

◆ TotalCapacity()

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

Returns configured backing capacity.

Returns
Capacity in bytes

Definition at line 108 of file fixed_stack_allocator.hpp.