CookMem 1.4.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
cookmem::CachedArena< Arena, TreeType > Class Template Reference

#include <arena.h>

Public Types

typedef TreeType PtrTreeType
 

Public Member Functions

 CachedArena (Arena &arena)
 
 ~CachedArena ()
 
 CachedArena (const CachedArena &)=delete
 
CachedArena & operator= (const CachedArena &)=delete
 
void * getSegment (std::size_t &size)
 
bool freeSegment (void *ptr, std::size_t size)
 
void releaseAll ()
 

Detailed Description

template<class Arena, class TreeType = PtrRBTree>
class cookmem::CachedArena< Arena, TreeType >

CachedArena is used to cache the segments released and see if they can be reused in the future segment request.

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.

Template Parameters
Arenathe memory arena that does the actual memory allocation
TreeTypeThe type of the tree used to cache the released segments. The default is PtrRBTree.

Member Typedef Documentation

◆ PtrTreeType

template<class Arena , class TreeType = PtrRBTree>
typedef TreeType cookmem::CachedArena< Arena, TreeType >::PtrTreeType

The type of the tree used to cache the released segments.

Constructor & Destructor Documentation

◆ CachedArena()

template<class Arena , class TreeType = PtrRBTree>
cookmem::CachedArena< Arena, TreeType >::CachedArena ( Arena &  arena)
inline

Constructor

Parameters
arenathe memory arena that does the actual memory allocation

◆ ~CachedArena()

template<class Arena , class TreeType = PtrRBTree>
cookmem::CachedArena< Arena, TreeType >::~CachedArena ( )
inline

Destructor. The cached segments are returned to the underlying arena.

Member Function Documentation

◆ freeSegment()

template<class Arena , class TreeType = PtrRBTree>
bool cookmem::CachedArena< Arena, TreeType >::freeSegment ( void *  ptr,
std::size_t  size 
)
inline

Free an arena segment.

The segment release is cached for the next get attempt that can be satisfied.

Parameters
ptrthe pointer to be freed.
sizethe size of the pointer.
Returns
false.

◆ getSegment()

template<class Arena , class TreeType = PtrRBTree>
void * cookmem::CachedArena< Arena, TreeType >::getSegment ( std::size_t &  size)
inline

Allocate an arena segment.

It first checks if there is a cached segment that could satisfy the request. If not, it calls the actual memory arena to allocate the 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 is allocation failed.

◆ releaseAll()

template<class Arena , class TreeType = PtrRBTree>
void cookmem::CachedArena< Arena, TreeType >::releaseAll ( )
inline

Return all the cached segments to the underlying arena. Segments that a memory pool is still using are not affected.


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