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

General-purpose PMR free-list allocator. More...

#include <free_list_allocator.hpp>

Inheritance diagram for helios::mem::FreeListAllocator:

Public Member Functions

 FreeListAllocator (FreeListAllocatorOptions options) noexcept
 Constructs free-list allocator from options.
 FreeListAllocator (size_t initial_capacity) noexcept
 Constructs free-list allocator with geometric growth.
 FreeListAllocator (const FreeListAllocator &)=delete
 FreeListAllocator (FreeListAllocator &&other) noexcept
 Move-constructs free-list allocator from another instance.
 ~FreeListAllocator () noexcept override
FreeListAllocatoroperator= (const FreeListAllocator &)=delete
FreeListAllocatoroperator= (FreeListAllocator &&other) noexcept
 Move-assigns free-list state from another instance.
void Reset () noexcept
 Resets allocator to initial state.
bool Empty () const noexcept
 Returns true when no allocations are active.
bool Owns (const void *ptr) const noexcept
 Checks whether pointer belongs to allocator storage.
AllocatorStats Stats () const noexcept
 Returns runtime stats.
size_t Capacity () const noexcept
 Returns total capacity across regions.
size_t UsedMemory () const noexcept
 Returns used memory bytes.
size_t FreeMemory () const noexcept
 Returns free memory bytes.
size_t FreeBlockCount () const noexcept
 Returns free-list block count.
size_t AllocationCount () const noexcept
 Returns current active allocation count.
GrowthPolicy Growth () const noexcept
 Returns growth policy.

Detailed Description

General-purpose PMR free-list allocator.

Best-fit free-list with coalescing under a mutex. Growable backing regions retire through epoch-based reclamation so Owns() can scan regions without holding the free-list mutex.

Definition at line 29 of file free_list_allocator.hpp.

Constructor & Destructor Documentation

◆ FreeListAllocator() [1/4]

helios::mem::FreeListAllocator::FreeListAllocator ( FreeListAllocatorOptions options)
inlineexplicitnoexcept

Constructs free-list allocator from options.

Warning
Triggers assertion if options.initial_capacity is too small or options.growth.max_capacity < options.initial_capacity.
Parameters
optionsAllocator options

Definition at line 189 of file free_list_allocator.hpp.

◆ FreeListAllocator() [2/4]

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

Constructs free-list allocator with geometric growth.

Warning
Triggers assertion when initial capacity is too small.
Parameters
initial_capacityInitial backing capacity

Definition at line 44 of file free_list_allocator.hpp.

◆ FreeListAllocator() [3/4]

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

◆ FreeListAllocator() [4/4]

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

Move-constructs free-list allocator from another instance.

Parameters
otherSource allocator; left in empty moved-from state

Definition at line 214 of file free_list_allocator.hpp.

◆ ~FreeListAllocator()

helios::mem::FreeListAllocator::~FreeListAllocator ( )
inlineoverridenoexcept

Definition at line 57 of file free_list_allocator.hpp.

Member Function Documentation

◆ AllocationCount()

size_t helios::mem::FreeListAllocator::AllocationCount ( ) const
inlinenodiscardnoexcept

Returns current active allocation count.

Returns
Number of active allocations

Definition at line 129 of file free_list_allocator.hpp.

◆ Capacity()

size_t helios::mem::FreeListAllocator::Capacity ( ) const
inlinenodiscardnoexcept

Returns total capacity across regions.

Returns
Capacity in bytes

Definition at line 99 of file free_list_allocator.hpp.

◆ Empty()

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

Returns true when no allocations are active.

Returns
True if empty, false otherwise

Definition at line 78 of file free_list_allocator.hpp.

◆ FreeBlockCount()

size_t helios::mem::FreeListAllocator::FreeBlockCount ( ) const
inlinenodiscardnoexcept

Returns free-list block count.

Returns
Number of free blocks

Definition at line 121 of file free_list_allocator.hpp.

◆ FreeMemory()

size_t helios::mem::FreeListAllocator::FreeMemory ( ) const
nodiscardnoexcept

Returns free memory bytes.

Returns
Free bytes

Definition at line 111 of file free_list_allocator.cpp.

◆ Growth()

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

Returns growth policy.

Returns
Growth policy

Definition at line 137 of file free_list_allocator.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Move-assigns free-list state from another instance.

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

Definition at line 220 of file free_list_allocator.hpp.

◆ Owns()

bool helios::mem::FreeListAllocator::Owns ( const void * ptr) const
nodiscardnoexcept

Checks whether pointer belongs to allocator storage.

Parameters
ptrPointer to test
Returns
True when owned, false otherwise

Definition at line 52 of file free_list_allocator.cpp.

◆ Reset()

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

Resets allocator to initial state.

Warning
Must not be called concurrently with allocate/deallocate.

Definition at line 31 of file free_list_allocator.cpp.

◆ Stats()

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

Returns runtime stats.

Returns
Allocator stats snapshot

Definition at line 232 of file free_list_allocator.hpp.

◆ UsedMemory()

size_t helios::mem::FreeListAllocator::UsedMemory ( ) const
inlinenodiscardnoexcept

Returns used memory bytes.

Returns
Used bytes

Definition at line 107 of file free_list_allocator.hpp.