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

Fixed-capacity intrusive block pool. More...

#include <fixed_pool_allocator.hpp>

Inheritance diagram for helios::mem::FixedPoolAllocator:

Public Member Functions

 FixedPoolAllocator (FixedPoolAllocatorOptions options) noexcept
 Constructs fixed pool from options.
 FixedPoolAllocator (size_t block_size, size_t block_count, size_t alignment=kDefaultAlignment) noexcept
 Constructs fixed pool with explicit block geometry.
 FixedPoolAllocator (const FixedPoolAllocator &)=delete
 FixedPoolAllocator (FixedPoolAllocator &&other) noexcept
 Move-constructs fixed pool from another instance.
 ~FixedPoolAllocator () noexcept override
FixedPoolAllocatoroperator= (const FixedPoolAllocator &)=delete
FixedPoolAllocatoroperator= (FixedPoolAllocator &&other) noexcept
 Move-assigns fixed pool state from another instance.
void Reset () noexcept
 Resets pool to fully free state.
bool Full () const noexcept
 Returns true when no free blocks remain.
bool Empty () const noexcept
 Returns true when all blocks are free.
bool Owns (const void *ptr) const noexcept
 Checks pointer ownership.
AllocatorStats Stats () const noexcept
 Returns runtime statistics snapshot.
size_t BlockSize () const noexcept
 Returns effective block size.
size_t Alignment () const noexcept
 Returns configured block alignment.
size_t InitialBlockCount () const noexcept
 Returns configured block count.
size_t BlockCount () const noexcept
 Returns configured block count.
size_t FreeBlockCount () const noexcept
 Returns free block count.
size_t UsedBlockCount () const noexcept
 Returns used block count.

Static Public Member Functions

template<typename T>
static FixedPoolAllocator ForType (size_t block_count) noexcept
 Helper for constructing fixed pool allocator for a specific type.

Detailed Description

Fixed-capacity intrusive block pool.

Lock-free Treiber free-list over a single preallocated chunk.

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

Definition at line 30 of file fixed_pool_allocator.hpp.

Constructor & Destructor Documentation

◆ FixedPoolAllocator() [1/4]

helios::mem::FixedPoolAllocator::FixedPoolAllocator ( FixedPoolAllocatorOptions options)
inlineexplicitnoexcept

Constructs fixed pool from options.

Warning
Triggers assertion when block_size or block_count is zero, or when alignment is invalid. Triggers verification failure if backing allocation fails.
Parameters
optionsFixed pool configuration

Definition at line 179 of file fixed_pool_allocator.hpp.

◆ FixedPoolAllocator() [2/4]

helios::mem::FixedPoolAllocator::FixedPoolAllocator ( size_t block_size,
size_t block_count,
size_t alignment = kDefaultAlignment )
inlinenoexcept

Constructs fixed pool with explicit block geometry.

Warning
Triggers assertion when block_size or block_count is zero, or when alignment is invalid.
Parameters
block_sizeMinimum payload size of each block in bytes
block_countNumber of blocks in the pool
alignmentBlock alignment in bytes

Definition at line 201 of file fixed_pool_allocator.hpp.

◆ FixedPoolAllocator() [3/4]

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

◆ FixedPoolAllocator() [4/4]

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

Move-constructs fixed pool from another instance.

Parameters
otherSource allocator; left in empty moved-from state

Definition at line 57 of file fixed_pool_allocator.hpp.

◆ ~FixedPoolAllocator()

helios::mem::FixedPoolAllocator::~FixedPoolAllocator ( )
inlineoverridenoexcept

Definition at line 58 of file fixed_pool_allocator.hpp.

Member Function Documentation

◆ Alignment()

size_t helios::mem::FixedPoolAllocator::Alignment ( ) const
inlinenodiscardnoexcept

Returns configured block alignment.

Returns
Alignment in bytes

Definition at line 123 of file fixed_pool_allocator.hpp.

◆ BlockCount()

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

Returns configured block count.

Returns
Number of blocks in the pool

Definition at line 137 of file fixed_pool_allocator.hpp.

◆ BlockSize()

size_t helios::mem::FixedPoolAllocator::BlockSize ( ) const
inlinenodiscardnoexcept

Returns effective block size.

Returns
Block size in bytes

Definition at line 117 of file fixed_pool_allocator.hpp.

◆ Empty()

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

Returns true when all blocks are free.

Returns
True if empty, false otherwise

Definition at line 96 of file fixed_pool_allocator.hpp.

◆ ForType()

template<typename T>
FixedPoolAllocator helios::mem::FixedPoolAllocator::ForType ( size_t block_count)
inlinestaticnodiscardnoexcept

Helper for constructing fixed pool allocator for a specific type.

Template Parameters
TType to pool
Parameters
block_countNumber of blocks in the pool
Returns
Configured fixed pool allocator

Definition at line 222 of file fixed_pool_allocator.hpp.

◆ FreeBlockCount()

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

Returns free block count.

Returns
Number of blocks currently on the free list

Definition at line 143 of file fixed_pool_allocator.hpp.

◆ Full()

bool helios::mem::FixedPoolAllocator::Full ( ) const
inlinenodiscardnoexcept

Returns true when no free blocks remain.

Returns
True if full, false otherwise

Definition at line 88 of file fixed_pool_allocator.hpp.

◆ InitialBlockCount()

size_t helios::mem::FixedPoolAllocator::InitialBlockCount ( ) const
inlinenodiscardnoexcept

Returns configured block count.

Returns
Number of blocks in the pool

Definition at line 129 of file fixed_pool_allocator.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Move-assigns fixed pool state from another instance.

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

Definition at line 210 of file fixed_pool_allocator.hpp.

◆ Owns()

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

Checks pointer ownership.

Parameters
ptrPointer to test
Returns
True when pointer belongs to this pool chunk, false otherwise

Definition at line 238 of file fixed_pool_allocator.hpp.

◆ Reset()

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

Resets pool to fully free state.

Warning
Must not be called concurrently with allocate or deallocate.

Definition at line 229 of file fixed_pool_allocator.hpp.

◆ Stats()

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

Returns runtime statistics snapshot.

Returns
Allocator stats for this pool

Definition at line 251 of file fixed_pool_allocator.hpp.

◆ UsedBlockCount()

size_t helios::mem::FixedPoolAllocator::UsedBlockCount ( ) const
inlinenodiscardnoexcept

Returns used block count.

Returns
Number of blocks currently allocated

Definition at line 151 of file fixed_pool_allocator.hpp.