ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
RTTRAllocator Struct Reference

Description:


This struct's name stands for "run-time type recycling allocator". The struct encapsulates an allocator and recycles (caches) objects whose size and alignment are only determined and detected at run-time.
This type should only be used in combination with struct StdContMARecycling or in similar (unlikely) situations when the type of recyclable objects is unknown at compile time.

It is provided by ALib to support recycling of monotonically allocated memory with container types provided by the C++ standard library. With those, the internal node types are unspecified. A typical implementation and use of the containers will always allocate the same object size. This is detected with the first allocation and from this point in time, future de-allocations will recycle pieces of memory of exactly this type.

If no MonoAllocator is given with construction, this recycler uses std::malloc and std::free for memory allocation and de-allocation. While such operation mode does not imply all performance benefits of monotonic allocation scenarios, still the recycling of node objects may avoid many malloc/free operations and therefore reduce memory fragmentation significantly.
Method RecycleChunk will not create recyclable objects in that mode, but will duly use std::free to directly free a chunk of non-object size.

Definition at line 62 of file rttrallocator.hpp.

#include <rttrallocator.hpp>

Collaboration diagram for RTTRAllocator:
[legend]

Inner Type Index:

struct  Node
 

Public Field Index:

MonoAllocatorallocator
 
const std::type_info * dbgDetectedObjectTypeInfo = nullptr
 
bool dbgWarnDeallocationPriorToAllocation = true
 
bool dbgWarnDifferentObjectTypeAlloc = true
 
bool dbgWarnDifferentObjectTypeDealloc = true
 
bool dbgWarnRecycleChunkPriorToAllocation = true
 
size_t detectedObjectAlignment = 0
 
size_t detectedObjectSize = 0
 
lang::SidiListHelper< Nodestack
 

Public Method Index:

 RTTRAllocator (MonoAllocator *pAllocator)
 
char * AllocUnrelated (size_t size, size_t alignment, const type_info &dbgTypeInfo)
 
char * Get (size_t size, size_t alignment, const type_info &dbgTypeInfo)
 
void Recycle (void *mem, size_t size, size_t alignment, const type_info &dbgTypeInfo)
 
void RecycleChunk (char *mem, size_t size, size_t alignment, const type_info &dbgTypeInfo)
 

Field Details:

◆ allocator

MonoAllocator* allocator

The monotonic allocator

Definition at line 70 of file rttrallocator.hpp.

◆ dbgDetectedObjectTypeInfo

const std::type_info* dbgDetectedObjectTypeInfo = nullptr

The detected object's run-time type information struct.
Available only in debug builds.

Definition at line 84 of file rttrallocator.hpp.

◆ dbgWarnDeallocationPriorToAllocation

bool dbgWarnDeallocationPriorToAllocation = true

Flag on raising an ALib warning. Defaults to true and set to false when a corresponding warning was given..
Available only in debug builds.

Definition at line 99 of file rttrallocator.hpp.

◆ dbgWarnDifferentObjectTypeAlloc

bool dbgWarnDifferentObjectTypeAlloc = true

Flag on raising an ALib warning. Defaults to true and set to false when a corresponding warning was given..
Available only in debug builds.

Definition at line 89 of file rttrallocator.hpp.

◆ dbgWarnDifferentObjectTypeDealloc

bool dbgWarnDifferentObjectTypeDealloc = true

Flag on raising an ALib warning. Defaults to true and set to false when a corresponding warning was given..
Available only in debug builds.

Definition at line 94 of file rttrallocator.hpp.

◆ dbgWarnRecycleChunkPriorToAllocation

bool dbgWarnRecycleChunkPriorToAllocation = true

Flag on raising an ALib warning. Defaults to true and set to false when a corresponding warning was given..
Available only in debug builds.

Definition at line 104 of file rttrallocator.hpp.

◆ detectedObjectAlignment

size_t detectedObjectAlignment = 0

The required object alignment. Will be detected with the first invocation of Get.

Definition at line 79 of file rttrallocator.hpp.

◆ detectedObjectSize

size_t detectedObjectSize = 0

The object size of recylables. Will be detected with the first invocation of Get.

Definition at line 76 of file rttrallocator.hpp.

◆ stack

List of destructed objects available for recycling.

Definition at line 73 of file rttrallocator.hpp.

Constructor(s) / Destructor Details::

◆ RTTRAllocator()

RTTRAllocator ( MonoAllocator * pAllocator)
inline

Constructor taking the monotonic allocator.

If nullptr is given, this recycler uses std::malloc and std::free for memory allocation and de-allocation.

Parameters
pAllocatorThe monotonic allocator. If nullptr is given, still recycling of node objects is performed.

Definition at line 116 of file rttrallocator.hpp.

Method Details:

◆ AllocUnrelated()

char * AllocUnrelated ( size_t size,
size_t alignment,
const type_info & dbgTypeInfo )
inline

Allocates memory for a type different to the dedicated, detected object type.

Parameters
sizeThe requested size.
alignmentThe requested alignment
dbgTypeInfoThe type information of the object to allocate. Available only in debug builds.
Returns
The requested memory.

◆ Get()

char * Get ( size_t size,
size_t alignment,
const type_info & dbgTypeInfo )
inline

Allocates or recycles memory for the dedicated object type. With the first invocation of this method, this type is determined object type. In debug builds, this method will raise an ALib warning in case a different object type is requested.

Parameters
sizeThe requested size.
alignmentThe requested alignment
dbgTypeInfoThe type information of the object to allocate. Available only in debug builds.
Returns
The requested memory.

◆ Recycle()

void Recycle ( void * mem,
size_t size,
size_t alignment,
const type_info & dbgTypeInfo )
inline

Deallocates memory for the dedicated, detected object type.

In debug builds, this method will raise an ALib warning in case a different object type is deallocated as had been detected. Furthermore, a warning is raised in case no previous call to Get has been performed.

Parameters
memThe object to deallocate.
sizeThe size of the object to deallocate.
alignmentThe alignment of the object to deallocate.
dbgTypeInfoThe type information of the object to de-allocate. Available only in debug builds.

◆ RecycleChunk()

void RecycleChunk ( char * mem,
size_t size,
size_t alignment,
const type_info & dbgTypeInfo )
inline

Deallocates memory for a type different to the dedicated, detected object type.

In debug builds, this method will raise an ALib warning no previous call to Get has been performed.
Furthermore, a warning is raised in case that the provided memory chunk is too small to be sliced into at least one recyclable object.

Parameters
memThe object to deallocate.
sizeThe size of the object to deallocate.
alignmentThe alignment of the object to deallocate.
dbgTypeInfoThe type information of the object to de-allocate. Available only in debug builds.

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