Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::mem::StackAllocator< CapacityInBytes > Class Template Reference

Stack allocator capable of instantiating any default-constructible object on stack. Every allocation comes with a 16-bytes long sentinel object. More...

#include <stack_allocator.h>

Public Member Functions

 StackAllocator (const StackAllocator &)=delete
 
 StackAllocator (StackAllocator &&)=delete
 
StackAllocatoroperator= (const StackAllocator &)=delete
 
StackAllocatoroperator= (StackAllocator &&)=delete
 
template<typename T >
GAIA_NODISCARD T * alloc (uint32_t cnt)
 Allocates objects inside the buffer. No default initialization is done so the object is returned in a non-initialized state unless a custom constructor is provided.
 
void free (void *pData, uint32_t cnt)
 Frees the last allocated object from the stack.
 
void reset ()
 Frees all allocated objects from the buffer.
 
GAIA_NODISCARD constexpr uint32_t capacity ()
 Returns the fixed buffer capacity.
 

Detailed Description

template<uint32_t CapacityInBytes = 1024>
class gaia::mem::StackAllocator< CapacityInBytes >

Stack allocator capable of instantiating any default-constructible object on stack. Every allocation comes with a 16-bytes long sentinel object.

Template Parameters
CapacityInBytesSize of the inline allocation buffer in bytes.

Member Function Documentation

◆ alloc()

template<uint32_t CapacityInBytes = 1024>
template<typename T >
GAIA_NODISCARD T * gaia::mem::StackAllocator< CapacityInBytes >::alloc ( uint32_t  cnt)
inline

Allocates objects inside the buffer. No default initialization is done so the object is returned in a non-initialized state unless a custom constructor is provided.

Template Parameters
TObject type.
Parameters
cntNumber of objects to allocate.
Returns
Pointer to the first allocated object

◆ capacity()

template<uint32_t CapacityInBytes = 1024>
GAIA_NODISCARD constexpr uint32_t gaia::mem::StackAllocator< CapacityInBytes >::capacity ( )
inlineconstexpr

Returns the fixed buffer capacity.

Returns
Capacity in bytes.

◆ free()

template<uint32_t CapacityInBytes = 1024>
void gaia::mem::StackAllocator< CapacityInBytes >::free ( void *  pData,
uint32_t  cnt 
)
inline

Frees the last allocated object from the stack.

Parameters
pDataPointer to the last allocated object on the stack
cntNumber of objects that were allocated on the given memory address

The documentation for this class was generated from the following file: