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

Public Types

using DataPointer = uint8_t *
 

Public Member Functions

 RandomAllocator ()
 
void Init (DataPointer data, size_t bytes)
 
 RandomAllocator (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) const
 

Constructor & Destructor Documentation

§ RandomAllocator() [1/2]

MxEngine::RandomAllocator::RandomAllocator ( )
inline

creates empty random allocator (first node == last node == nullptr)

§ RandomAllocator() [2/2]

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

constructs random 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::RandomAllocator::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::RandomAllocator::Dump ( std::ostream &  out) const
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::RandomAllocator::Free ( T *  ptr)
inline

destroyes object of type T, calling its destructor

Parameters
valueobject to destroy

§ GetBase()

DataPointer MxEngine::RandomAllocator::GetBase ( )
inline

memory chunk getter

Returns
pointer to begin of memory chunk

§ Init()

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

assigns new memory chunk to random allocator

Parameters
databegin of memory chunk
bytessize in bytes of memory chunk

§ RawAlloc()

DataPointer MxEngine::RandomAllocator::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::RandomAllocator::RawFree ( uint8_t *  ptr)
inline

frees raw allocated memory by pointer to its begin

Parameters
ptrpointer to deallocate

§ StackAlloc()

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

constructs object of type T

Parameters
argsarguments for object construction
Returns
smart pointer to object with custom deleter

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