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

Fixed-capacity best-fit allocator with coalescing. More...

#include <fixed_free_list_allocator.hpp>

Inheritance diagram for helios::mem::FixedFreeListAllocator:

Public Member Functions

 FixedFreeListAllocator (size_t capacity) noexcept
 Constructs fixed free-list with the given backing capacity.
 FixedFreeListAllocator (const FixedFreeListAllocator &)=delete
 FixedFreeListAllocator (FixedFreeListAllocator &&other) noexcept
 Move-constructs fixed free-list from another instance.
 ~FixedFreeListAllocator () noexcept override
FixedFreeListAllocatoroperator= (const FixedFreeListAllocator &)=delete
FixedFreeListAllocatoroperator= (FixedFreeListAllocator &&other) noexcept
 Move-assigns fixed free-list state from another instance.
void Reset () noexcept
 Resets allocator to a single free region.
bool Empty () const noexcept
 Returns true when no allocations are active.
bool Owns (const void *ptr) const noexcept
 Checks whether pointer belongs to this allocator's backing buffer.
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.
size_t FreeBlockCount () const noexcept
 Returns free-list block count.

Detailed Description

Fixed-capacity best-fit allocator with coalescing.

Mutex-protected variable-size allocations inside one region.

Warning
Reset() must not run concurrently with allocate or deallocate.

Definition at line 23 of file fixed_free_list_allocator.hpp.

Constructor & Destructor Documentation

◆ FixedFreeListAllocator() [1/3]

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

Constructs fixed free-list 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 136 of file fixed_free_list_allocator.hpp.

◆ FixedFreeListAllocator() [2/3]

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

◆ FixedFreeListAllocator() [3/3]

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

Move-constructs fixed free-list from another instance.

Parameters
otherSource allocator; left in empty moved-from state

Definition at line 149 of file fixed_free_list_allocator.hpp.

◆ ~FixedFreeListAllocator()

helios::mem::FixedFreeListAllocator::~FixedFreeListAllocator ( )
inlineoverridenoexcept

Definition at line 39 of file fixed_free_list_allocator.hpp.

Member Function Documentation

◆ Empty()

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

Returns true when no allocations are active.

Returns
True if empty, false otherwise

Definition at line 60 of file fixed_free_list_allocator.hpp.

◆ FreeBlockCount()

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

Returns free-list block count.

Returns
Number of disjoint free blocks

Definition at line 93 of file fixed_free_list_allocator.hpp.

◆ InitialCapacity()

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

Returns configured backing capacity.

Returns
Capacity in bytes

Definition at line 81 of file fixed_free_list_allocator.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Move-assigns fixed free-list state from another instance.

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

Definition at line 155 of file fixed_free_list_allocator.hpp.

◆ Owns()

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

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

Parameters
ptrPointer to test
Returns
True when owned, false otherwise

Definition at line 178 of file fixed_free_list_allocator.hpp.

◆ Reset()

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

Resets allocator to a single free region.

Warning
Must not be called concurrently with allocate or deallocate.

Definition at line 167 of file fixed_free_list_allocator.hpp.

◆ Stats()

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

Returns runtime statistics snapshot.

Returns
Allocator stats for this free-list

Definition at line 195 of file fixed_free_list_allocator.hpp.

◆ TotalCapacity()

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

Returns configured backing capacity.

Returns
Capacity in bytes

Definition at line 87 of file fixed_free_list_allocator.hpp.