Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
helios::app::PoolAllocatorResource Class Reference

#include <allocator_resources.hpp>

Public Member Functions

 PoolAllocatorResource (size_t block_size, size_t block_count, size_t alignment=memory::kDefaultAlignment)
 Constructs resource with a pool allocator.
 
 PoolAllocatorResource (const PoolAllocatorResource &)=delete
 
 PoolAllocatorResource (PoolAllocatorResource &&) noexcept=default
 
 ~PoolAllocatorResource () noexcept=default
 
PoolAllocatorResourceoperator= (const PoolAllocatorResource &)=delete
 
PoolAllocatorResourceoperator= (PoolAllocatorResource &&) noexcept=default
 
memory::PoolAllocatorGet () noexcept
 Gets reference to the pool allocator.
 
const memory::PoolAllocatorGet () const noexcept
 Gets const reference to the pool allocator.
 
void Reset () noexcept
 Resets the pool, making all blocks available.
 
bool Empty () const noexcept
 Checks if the pool allocator is empty.
 
bool Full () const noexcept
 Checks if the pool allocator is full.
 
memory::AllocatorStats Stats () const noexcept
 Gets pool allocator statistics.
 
size_t BlockSize () const noexcept
 Gets the block size.
 
size_t BlockCount () const noexcept
 Gets the block count.
 

Static Public Member Functions

template<typename T >
static PoolAllocatorResource ForType (size_t block_count)
 Creates a pool allocator resource sized for type T.
 
static constexpr std::string_view Name () noexcept
 Gets the resource name for registration.
 

Detailed Description

Definition at line 197 of file allocator_resources.hpp.

Constructor & Destructor Documentation

◆ PoolAllocatorResource() [1/3]

helios::app::PoolAllocatorResource::PoolAllocatorResource ( size_t  block_size,
size_t  block_count,
size_t  alignment = memory::kDefaultAlignment 
)
inlineexplicit

Constructs resource with a pool allocator.

Parameters
block_sizeSize of each block in bytes
block_countNumber of blocks to allocate
alignmentAlignment for each block (must be power of 2)

Definition at line 216 of file allocator_resources.hpp.

217 : allocator_(block_size, block_count, alignment) {}

◆ PoolAllocatorResource() [2/3]

helios::app::PoolAllocatorResource::PoolAllocatorResource ( const PoolAllocatorResource )
delete

◆ PoolAllocatorResource() [3/3]

helios::app::PoolAllocatorResource::PoolAllocatorResource ( PoolAllocatorResource &&  )
defaultnoexcept

◆ ~PoolAllocatorResource()

helios::app::PoolAllocatorResource::~PoolAllocatorResource ( )
defaultnoexcept

Member Function Documentation

◆ BlockCount()

size_t helios::app::PoolAllocatorResource::BlockCount ( ) const
inlinenoexcept

Gets the block count.

Returns
Total number of blocks
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 271 of file allocator_resources.hpp.

271{ return allocator_.BlockCount(); }
size_t BlockCount() const noexcept
Gets the block count.

◆ BlockSize()

size_t helios::app::PoolAllocatorResource::BlockSize ( ) const
inlinenoexcept

Gets the block size.

Returns
Block size in bytes
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 265 of file allocator_resources.hpp.

265{ return allocator_.BlockSize(); }
size_t BlockSize() const noexcept
Gets the block size.

◆ Empty()

bool helios::app::PoolAllocatorResource::Empty ( ) const
inlinenoexcept

Checks if the pool allocator is empty.

Returns
True if all blocks are free
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 247 of file allocator_resources.hpp.

247{ return allocator_.Empty(); }

◆ ForType()

template<typename T >
static PoolAllocatorResource helios::app::PoolAllocatorResource::ForType ( size_t  block_count)
inlinestatic

Creates a pool allocator resource sized for type T.

Template Parameters
TType to allocate
Parameters
block_countNumber of blocks to allocate
Returns
PoolAllocatorResource configured for type T
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 206 of file allocator_resources.hpp.

206 {
207 return PoolAllocatorResource(sizeof(T), block_count, alignof(T));
208 }
PoolAllocatorResource(size_t block_size, size_t block_count, size_t alignment=memory::kDefaultAlignment)
Constructs resource with a pool allocator.

◆ Full()

bool helios::app::PoolAllocatorResource::Full ( ) const
inlinenoexcept

Checks if the pool allocator is full.

Returns
True if all blocks are allocated
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 253 of file allocator_resources.hpp.

253{ return allocator_.Full(); }
bool Full() const noexcept
Checks if the allocator is full.

◆ Get() [1/2]

const memory::PoolAllocator & helios::app::PoolAllocatorResource::Get ( ) const
inlinenoexcept

Gets const reference to the pool allocator.

Returns
Const reference to PoolAllocator

Definition at line 236 of file allocator_resources.hpp.

236{ return allocator_; }

◆ Get() [2/2]

memory::PoolAllocator & helios::app::PoolAllocatorResource::Get ( )
inlinenoexcept

Gets reference to the pool allocator.

Returns
Reference to PoolAllocator
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 230 of file allocator_resources.hpp.

230{ return allocator_; }

◆ Name()

static constexpr std::string_view helios::app::PoolAllocatorResource::Name ( )
inlinestaticconstexprnoexcept

Gets the resource name for registration.

Returns
Resource name
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 277 of file allocator_resources.hpp.

277{ return "PoolAllocatorResource"; }

◆ operator=() [1/2]

◆ operator=() [2/2]

PoolAllocatorResource & helios::app::PoolAllocatorResource::operator= ( PoolAllocatorResource &&  )
defaultnoexcept

◆ Reset()

void helios::app::PoolAllocatorResource::Reset ( )
inlinenoexcept

Resets the pool, making all blocks available.

Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 241 of file allocator_resources.hpp.

241{ allocator_.Reset(); }
void Reset() noexcept
Resets the pool, making all blocks available.

◆ Stats()

memory::AllocatorStats helios::app::PoolAllocatorResource::Stats ( ) const
inlinenoexcept

Gets pool allocator statistics.

Returns
AllocatorStats with current usage
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/allocator_resources.hpp.

Definition at line 259 of file allocator_resources.hpp.

259{ return allocator_.Stats(); }
AllocatorStats Stats() const noexcept
Gets current allocator statistics.