CookMem 1.4.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
cookmem::FixedArena Class Reference

#include <arena.h>

Public Member Functions

 FixedArena (void *ptr, std::size_t size)
 
void * getSegment (std::size_t &size)
 
bool freeSegment (void *ptr, std::size_t size)
 
void releaseAll ()
 

Detailed Description

This memory arena simply wraps around a piece of memory which is used for memory allocation.

This class implements the interface of MemArena without explicitly inheriting from it. This is to avoid the overhead of virtual function calls and allows inlining of the functions.

Constructor & Destructor Documentation

◆ FixedArena()

cookmem::FixedArena::FixedArena ( void *  ptr,
std::size_t  size 
)
inline

Constructor.

Parameters
ptrthe memory buffer for memory allocation. If it is not aligned to ALLOCATION_ALIGNMENT, the start address is advanced to the next aligned address.
sizeThe size of the memory buffer. The usable size is reduced by any bytes skipped to align the start address, then rounded down to a multiple of ALLOCATION_ALIGNMENT.

Member Function Documentation

◆ freeSegment()

bool cookmem::FixedArena::freeSegment ( void *  ptr,
std::size_t  size 
)
inline

Free an arena segment.

Parameters
ptrthe pointer to be freed.
sizethe size of the pointer.
Returns
true if there is an error. false is okay.

◆ getSegment()

void * cookmem::FixedArena::getSegment ( std::size_t &  size)
inline

Allocate an arena segment.

Parameters
[in,out]sizethe size of the page. This value is updated upon successful request to indicate the actual size obtained.
Returns
the allocated pointer. nullptr if allocation failed.

◆ releaseAll()

void cookmem::FixedArena::releaseAll ( )
inline

Release all segments held by this arena. The buffer belongs to the caller, so this function does nothing.


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