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

N-buffered PMR frame allocator. More...

#include <frame_allocator.hpp>

Inheritance diagram for helios::mem::FrameAllocator< N >:

Public Member Functions

 FrameAllocator (FrameAllocatorOptions options) noexcept
 Constructs N-frame allocator from options.
 FrameAllocator (size_t initial_capacity) noexcept
 Constructs N-frame allocator with geometrically growing arenas.
 FrameAllocator (const FrameAllocator &)=delete
 FrameAllocator (FrameAllocator &&other) noexcept
 Move-constructs frame allocator from another instance.
 ~FrameAllocator () noexcept override=default
FrameAllocatoroperator= (const FrameAllocator &)=delete
FrameAllocatoroperator= (FrameAllocator &&other) noexcept
 Move-assigns frame allocator state from another instance.
void Advance () noexcept
 Advances to the next frame and resets its arena.
void Reset () noexcept
 Resets all frame arenas and returns to frame zero.
bool Empty () const noexcept
 Returns true when current frame arena has no allocations.
AllocatorStats Stats () const noexcept
 Returns stats for current frame arena.
AllocatorStats AggregateStats () const noexcept
 Returns aggregated stats across all frame arenas.
size_t FrameIndex () const noexcept
 Returns current frame index.
size_t InitialCapacity () const noexcept
 Returns per-arena initial capacity.
GrowthPolicy Growth () const noexcept
 Returns growth policy.
size_t TotalCapacity () const noexcept
 Returns current arena total capacity.
size_t BlockCount () const noexcept
 Returns current arena block count.
ArenaAllocatorArena (size_t index) noexcept
 Returns mutable arena by frame index.
const ArenaAllocatorArena (size_t index) const noexcept
 Returns const arena by frame index.

Static Public Member Functions

static consteval size_t FrameCount () noexcept
 Returns number of frame buffers.

Detailed Description

template<size_t N = 2>
requires (N >= 1)
class helios::mem::FrameAllocator< N >

N-buffered PMR frame allocator.

Holds N arena resources and routes allocations to current frame.

Advance() switches to the next frame and resets it, allowing memory reuse with deterministic lifetime windows.

Note
Allocation is thread-safe as delegated to ArenaAllocator.
Warning
Advance() and Reset() must not run concurrently with allocate.
Template Parameters
NNumber of frame buffers, must be >= 1

Definition at line 40 of file frame_allocator.hpp.

Constructor & Destructor Documentation

◆ FrameAllocator() [1/4]

template<size_t N>
requires (N >= 1)
helios::mem::FrameAllocator< N >::FrameAllocator ( FrameAllocatorOptions options)
inlineexplicitnoexcept

Constructs N-frame allocator from options.

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

Definition at line 217 of file frame_allocator.hpp.

◆ FrameAllocator() [2/4]

template<size_t N = 2>
helios::mem::FrameAllocator< N >::FrameAllocator ( size_t initial_capacity)
inlineexplicitnoexcept

Constructs N-frame allocator with geometrically growing arenas.

Warning
Triggers assertion if initial_capacity == 0.
Parameters
initial_capacityInitial per-frame arena capacity

Definition at line 55 of file frame_allocator.hpp.

◆ FrameAllocator() [3/4]

template<size_t N = 2>
helios::mem::FrameAllocator< N >::FrameAllocator ( const FrameAllocator< N > & )
delete

◆ FrameAllocator() [4/4]

template<size_t N = 2>
helios::mem::FrameAllocator< N >::FrameAllocator ( FrameAllocator< N > && other)
inlinenoexcept

Move-constructs frame allocator from another instance.

Parameters
otherSource allocator; frame index and arenas are transferred

Definition at line 66 of file frame_allocator.hpp.

◆ ~FrameAllocator()

template<size_t N = 2>
helios::mem::FrameAllocator< N >::~FrameAllocator ( )
overridedefaultnoexcept

Member Function Documentation

◆ Advance()

template<size_t N>
requires (N >= 1)
void helios::mem::FrameAllocator< N >::Advance ( )
inlinenoexcept

Advances to the next frame and resets its arena.

Wraps the frame index modulo N. The newly current arena is soft-reset, reclaiming all prior allocations in that slot.

Warning
Must not be called concurrently with allocate or deallocate.

Definition at line 248 of file frame_allocator.hpp.

◆ AggregateStats()

template<size_t N>
requires (N >= 1)
AllocatorStats helios::mem::FrameAllocator< N >::AggregateStats ( ) const
inlinenodiscardnoexcept

Returns aggregated stats across all frame arenas.

Returns
Summed allocator stats

Definition at line 269 of file frame_allocator.hpp.

◆ Arena() [1/2]

template<size_t N>
requires (N >= 1)
const ArenaAllocator & helios::mem::FrameAllocator< N >::Arena ( size_t index) const
inlinenodiscardnoexcept

Returns const arena by frame index.

Warning
Triggers assertion if index >= N.
Parameters
indexArena index
Returns
Const arena reference

Definition at line 298 of file frame_allocator.hpp.

◆ Arena() [2/2]

template<size_t N>
requires (N >= 1)
ArenaAllocator & helios::mem::FrameAllocator< N >::Arena ( size_t index)
inlinenodiscardnoexcept

Returns mutable arena by frame index.

Warning
Triggers assertion if index >= N.
Parameters
indexArena index
Returns
Arena reference

Definition at line 291 of file frame_allocator.hpp.

◆ BlockCount()

template<size_t N = 2>
size_t helios::mem::FrameAllocator< N >::BlockCount ( ) const
inlinenodiscardnoexcept

Returns current arena block count.

Returns
Block count

Definition at line 154 of file frame_allocator.hpp.

◆ Empty()

template<size_t N = 2>
bool helios::mem::FrameAllocator< N >::Empty ( ) const
inlinenodiscardnoexcept

Returns true when current frame arena has no allocations.

Returns
True if current arena is empty, false otherwise

Definition at line 100 of file frame_allocator.hpp.

◆ FrameCount()

template<size_t N = 2>
consteval size_t helios::mem::FrameAllocator< N >::FrameCount ( )
inlinestaticnodiscardconstevalnoexcept

Returns number of frame buffers.

Returns
N

Definition at line 126 of file frame_allocator.hpp.

◆ FrameIndex()

template<size_t N = 2>
size_t helios::mem::FrameAllocator< N >::FrameIndex ( ) const
inlinenodiscardnoexcept

Returns current frame index.

Returns
Current frame in range [0, N)

Definition at line 120 of file frame_allocator.hpp.

◆ Growth()

template<size_t N = 2>
GrowthPolicy helios::mem::FrameAllocator< N >::Growth ( ) const
inlinenodiscardnoexcept

Returns growth policy.

Returns
Growth policy

Definition at line 140 of file frame_allocator.hpp.

◆ InitialCapacity()

template<size_t N = 2>
size_t helios::mem::FrameAllocator< N >::InitialCapacity ( ) const
inlinenodiscardnoexcept

Returns per-arena initial capacity.

Returns
Capacity in bytes

Definition at line 132 of file frame_allocator.hpp.

◆ operator=() [1/2]

template<size_t N = 2>
FrameAllocator & helios::mem::FrameAllocator< N >::operator= ( const FrameAllocator< N > & )
delete

◆ operator=() [2/2]

template<size_t N>
requires (N >= 1)
FrameAllocator< N > & helios::mem::FrameAllocator< N >::operator= ( FrameAllocator< N > && other)
inlinenoexcept

Move-assigns frame allocator state from another instance.

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

Definition at line 227 of file frame_allocator.hpp.

◆ Reset()

template<size_t N>
requires (N >= 1)
void helios::mem::FrameAllocator< N >::Reset ( )
inlinenoexcept

Resets all frame arenas and returns to frame zero.

Warning
Must not be called concurrently with allocate or deallocate.

Definition at line 258 of file frame_allocator.hpp.

◆ Stats()

template<size_t N = 2>
AllocatorStats helios::mem::FrameAllocator< N >::Stats ( ) const
inlinenodiscardnoexcept

Returns stats for current frame arena.

Returns
Allocator stats

Definition at line 106 of file frame_allocator.hpp.

◆ TotalCapacity()

template<size_t N = 2>
size_t helios::mem::FrameAllocator< N >::TotalCapacity ( ) const
inlinenodiscardnoexcept

Returns current arena total capacity.

Returns
Capacity in bytes

Definition at line 146 of file frame_allocator.hpp.