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

#include <mallocarena.h>

Public Member Functions

 MallocArena (std::size_t minSize=DEFAULT_MIN_SEGMENT_SIZE)
 
void * getSegment (std::size_t &size)
 
bool freeSegment (void *ptr, std::size_t)
 
void releaseAll ()
 

Detailed Description

An malloc/free based memory arena.

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

◆ MallocArena()

cookmem::MallocArena::MallocArena ( std::size_t  minSize = DEFAULT_MIN_SEGMENT_SIZE)
inline

Constructor.

Parameters
minSizeminimum segment size. It should be noted that this value needs to be a multiple of 16.

Member Function Documentation

◆ freeSegment()

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

Free an arena segment using free.

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

◆ getSegment()

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

Allocate an arena segment using malloc.

Parameters
sizethe size of the segment. This value is updated upon successful request to indicate the actual size obtained.
Returns
the allocated pointer. nullptr is allocation failed.

◆ releaseAll()

void cookmem::MallocArena::releaseAll ( )
inline

Release all segments held by this arena. This arena does not keep any segments, so this function does nothing.


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