MxEngine
Public Types | Public Member Functions | List of all members
MxEngine::StackAllocator Class Reference

Public Types

using DataPointer = uint8_t *
 

Public Member Functions

 StackAllocator ()
 
void Init (DataPointer data, size_t bytes)
 
 StackAllocator (DataPointer data, size_t bytes)
 
DataPointer GetBase ()
 
DataPointer RawAlloc (size_t bytes, size_t align=1)
 
void RawFree (uint8_t *ptr)
 
template<typename T , typename... Args>
T * Alloc (Args &&... args)
 
template<typename T , typename... Args>
auto StackAlloc (Args &&... args)
 
template<typename T >
void Free (T *ptr)
 
void Dump (std::ostream &out)
 

Constructor & Destructor Documentation

§ StackAllocator() [1/2]

MxEngine::StackAllocator::StackAllocator ( )
inline

creates empty stack allocator (nullptr chunk pointer, size = 0)

§ StackAllocator() [2/2]

MxEngine::StackAllocator::StackAllocator ( DataPointer  data,
size_t  bytes 
)
inline

constructs stack allocator, assigning it memory chunk

Parameters
databegin of memory chunk
bytessize in bytes of memory chunk

Member Function Documentation

§ Alloc()

template<typename T , typename... Args>
T* MxEngine::StackAllocator::Alloc ( Args &&...  args)
inline

constructs object of type T in memory and returns pointer to it

Parameters
argsarguments for object construction
Returns
pointer to unmanaged object

§ Dump()

void MxEngine::StackAllocator::Dump ( std::ostream &  out)
inline

prints whole memory chunk byte by byte in hex format into stream provided

Parameters
outstream to output to

§ Free()

template<typename T >
void MxEngine::StackAllocator::Free ( T *  ptr)
inline

destroyes object of type T, calling its destructor

Parameters
valueobject to destroy
Warning
ptr MUST be a pointer to last allocated object, calling Free on some other object will probably result in crash

§ GetBase()

DataPointer MxEngine::StackAllocator::GetBase ( )
inline

memory chunk getter

Returns
pointer to begin of memory chunk

§ Init()

void MxEngine::StackAllocator::Init ( DataPointer  data,
size_t  bytes 
)
inline

assigns new memory chunk to stack allocator

Parameters
databegin of memory chunk
bytessize in bytes of memory chunk

§ RawAlloc()

DataPointer MxEngine::StackAllocator::RawAlloc ( size_t  bytes,
size_t  align = 1 
)
inline

returns pointer to raw allocated memory

Parameters
bytesminimal requested block size
alignminimal alignment of pointer (defaults to 1)
Returns
pointer to memory

§ RawFree()

void MxEngine::StackAllocator::RawFree ( uint8_t *  ptr)
inline

frees raw allocated memory by pointer to its begin

Parameters
ptrpointer to deallocate
Warning
ptr MUST be a pointer to last allocated chunk, calling RawFree on some other chunk will probably result in crash

§ StackAlloc()

template<typename T , typename... Args>
auto MxEngine::StackAllocator::StackAlloc ( Args &&...  args)
inline

constructs object of type T

Parameters
argsarguments for object construction
Returns
smart pointer to object with custom deleter
Warning
you should NOT change order of destruction of allocated objects (by moving them, for example) in any way, as it will probably results in crash

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