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

#include <mmaparena.h>

Public Member Functions

 MmapArena (std::size_t minSize=DEFAULT_MIN_SEGMENT_SIZE, int prot=(PROT_READ|PROT_WRITE), int flag=(MAP_PRIVATE|MAP_ANONYMOUS))
 
void * getSegment (std::size_t &size)
 
bool freeSegment (void *ptr, std::size_t size)
 
void releaseAll ()
 

Detailed Description

An mmap/munmap 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

◆ MmapArena()

cookmem::MmapArena::MmapArena ( std::size_t  minSize = DEFAULT_MIN_SEGMENT_SIZE,
int  prot = ( PROT_READ | PROT_WRITE ),
int  flag = ( MAP_PRIVATE | MAP_ANONYMOUS ) 
)
inline

Constructor.

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

Member Function Documentation

◆ freeSegment()

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

Free an arena segment using munamp().

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

◆ getSegment()

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

Allocate an arena segment using mmap().

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