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

PMR arena allocator with lock-free hot allocation path. More...

#include <arena_allocator.hpp>

Inheritance diagram for helios::mem::ArenaAllocator:

Public Member Functions

 ArenaAllocator (ArenaOptions options={}) noexcept
 Constructs arena allocator from options.
 ArenaAllocator (size_t initial_capacity) noexcept
 Constructs arena allocator with geometric growth.
 ArenaAllocator (const ArenaAllocator &)=delete
 ArenaAllocator (ArenaAllocator &&other) noexcept
 Move-constructs arena allocator from another instance.
 ~ArenaAllocator () noexcept override
ArenaAllocatoroperator= (const ArenaAllocator &)=delete
ArenaAllocatoroperator= (ArenaAllocator &&other) noexcept
 Move-assigns arena state from another instance.
void Reset () noexcept
 Soft-resets all block bump pointers to zero.
bool Empty () const noexcept
 Returns true when no allocations are currently active.
AllocatorStats Stats () const noexcept
 Returns allocator statistics snapshot.
size_t TotalCapacity () const noexcept
 Returns total capacity across all active blocks.
size_t InitialCapacity () const noexcept
 Returns initial block capacity.
size_t BlockCount () const noexcept
 Returns current number of blocks.
GrowthPolicy Growth () const noexcept
 Returns configured growth policy.

Detailed Description

PMR arena allocator with lock-free hot allocation path.

Individual deallocation is a no-op, matching monotonic arena semantics. Memory is reclaimed by Reset() or destruction.

Note
Thread-safe for allocate and deallocate.
Warning
Reset() must not run concurrently with allocation/deallocation.

Definition at line 30 of file arena_allocator.hpp.

Constructor & Destructor Documentation

◆ ArenaAllocator() [1/4]

helios::mem::ArenaAllocator::ArenaAllocator ( ArenaOptions options = {})
explicitnoexcept

Constructs arena allocator from options.

Warning
Triggers assertion if options.initial_capacity == 0 or options.growth.max_capacity < options.initial_capacity.
Parameters
optionsArena configuration

Definition at line 18 of file arena_allocator.cpp.

◆ ArenaAllocator() [2/4]

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

Constructs arena allocator with geometric growth.

Warning
Triggers assertion if initial_capacity == 0.
Parameters
initial_capacityCapacity of initial block in bytes

Definition at line 45 of file arena_allocator.hpp.

◆ ArenaAllocator() [3/4]

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

◆ ArenaAllocator() [4/4]

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

Move-constructs arena allocator from another instance.

Parameters
otherSource allocator; left in empty moved-from state

Definition at line 55 of file arena_allocator.hpp.

◆ ~ArenaAllocator()

helios::mem::ArenaAllocator::~ArenaAllocator ( )
inlineoverridenoexcept

Definition at line 56 of file arena_allocator.hpp.

Member Function Documentation

◆ BlockCount()

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

Returns current number of blocks.

Returns
Block count

Definition at line 113 of file arena_allocator.hpp.

◆ Empty()

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

Returns true when no allocations are currently active.

Uses a monotonic allocation counter; stays false after any allocation until Reset() even though individual deallocations are no-ops.

Returns
True if arena is empty, false otherwise

Definition at line 83 of file arena_allocator.hpp.

◆ Growth()

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

Returns configured growth policy.

Returns
Growth policy

Definition at line 121 of file arena_allocator.hpp.

◆ InitialCapacity()

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

Returns initial block capacity.

Returns
Initial capacity in bytes

Definition at line 105 of file arena_allocator.hpp.

◆ operator=() [1/2]

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

Move-assigns arena state from another instance.

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

Definition at line 176 of file arena_allocator.hpp.

◆ operator=() [2/2]

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

◆ Reset()

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

Soft-resets all block bump pointers to zero.

All existing allocations become logically invalid. Blocks are kept allocated and offsets reset to the start, allowing immediate reuse.

Warning
Must not be called concurrently with allocate.

Definition at line 34 of file arena_allocator.cpp.

◆ Stats()

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

Returns allocator statistics snapshot.

Returns
AllocatorStats for this arena

Definition at line 187 of file arena_allocator.hpp.

◆ TotalCapacity()

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

Returns total capacity across all active blocks.

Returns
Capacity in bytes

Definition at line 97 of file arena_allocator.hpp.