Gaia-ECS v0.9.3
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.
 
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 ()
 

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.

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.

Parameters
cntobjects of type
Template Parameters
Tinside the buffer. No default initialization is done so the object is returned in a non-initialized state unless a custom constructor is provided.
Returns
Pointer to the first allocated object

◆ 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: