ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
RTTRAllocator< TAllocator > Struct Template Reference

Description:

template<typename TAllocator>
struct alib::lang::RTTRAllocator< TAllocator >

This structs' 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 StdContainerAllocatorRecycling or in similar (unlikely) situations when the type of recyclable objects is unknown at compile time.

Note
The reason why the size of node types of containers of the C++ standard library is known only at run-time, is that the implementation of the containers is not standardized. Hence, in fact the node size is of course known at compile time, it is just not accessible in a platform-independent fashion.

This type 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 type lang::HeapAllocator is given as template parameter TAllocator, 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.

Template Parameters
TAllocatorThe allocator type, as prototyped with Allocator.

Definition at line 69 of file rttrallocator.hpp.

#include <rttrallocator.hpp>

Inheritance diagram for RTTRAllocator< TAllocator >:
[legend]
Collaboration diagram for RTTRAllocator< TAllocator >:
[legend]

Inner Type Index:

struct  Node
 

Public Type Index:

using allocBase = AllocatorMember<TAllocator>
 The allocator type that TAllocator specifies.
 
- Public Type Index: inherited from AllocatorMember< TAllocator >
using AllocatorType = TAllocator
 Exposes the allocator type.
 

Public Field Index:

const std::type_info * dbgDetectedObjectTypeInfo = nullptr
 
bool dbgWarnDeallocationPriorToAllocation = true
 
bool dbgWarnDifferentObjectTypeAlloc = true
 
bool dbgWarnDifferentObjectTypeDealloc = true
 
bool dbgWarnRecycleChunkPriorToAllocation = true
 
size_t detectedObjectAlignment = 0
 The required object alignment. Will be detected with the first invocation of Get.
 
size_t detectedObjectSize = 0
 The object size of recyclables. Will be detected with the first invocation of Get.
 
SidiListHook< Nodestack
 List of destructed objects available for recycling.
 

Public Method Index:

 RTTRAllocator (TAllocator &pAllocator) noexcept
 
void * AllocUnrelated (size_t size, size_t alignment, const type_info &dbgTypeInfo)
 
void * 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 (void *mem, size_t size, const type_info &dbgTypeInfo)
 
- Public Method Index: inherited from AllocatorMember< TAllocator >
 AllocatorMember ()=delete
 Deleted default constructor. (The allocator has to be given with construction)
 
 AllocatorMember (TAllocator &pAllocator) noexcept
 
AllocatorInterface< TAllocator > AI () const noexcept
 
TAllocator & GetAllocator () const noexcept
 

Additional Inherited Members

- Protected Field Index: inherited from AllocatorMember< TAllocator >
TAllocator & allocator
 A reference to the allocator.
 

Type Definition Details:

◆ allocBase

template<typename TAllocator >
using allocBase = AllocatorMember<TAllocator>

The allocator type that TAllocator specifies.

Definition at line 72 of file rttrallocator.hpp.

Field Details:

◆ dbgDetectedObjectTypeInfo

template<typename TAllocator >
const std::type_info* dbgDetectedObjectTypeInfo = nullptr

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

Definition at line 91 of file rttrallocator.hpp.

◆ dbgWarnDeallocationPriorToAllocation

template<typename TAllocator >
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 106 of file rttrallocator.hpp.

◆ dbgWarnDifferentObjectTypeAlloc

template<typename TAllocator >
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 96 of file rttrallocator.hpp.

◆ dbgWarnDifferentObjectTypeDealloc

template<typename TAllocator >
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 101 of file rttrallocator.hpp.

◆ dbgWarnRecycleChunkPriorToAllocation

template<typename TAllocator >
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 111 of file rttrallocator.hpp.

◆ detectedObjectAlignment

template<typename TAllocator >
size_t detectedObjectAlignment = 0

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

Definition at line 86 of file rttrallocator.hpp.

◆ detectedObjectSize

template<typename TAllocator >
size_t detectedObjectSize = 0

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

Definition at line 83 of file rttrallocator.hpp.

◆ stack

template<typename TAllocator >
SidiListHook<Node> stack

List of destructed objects available for recycling.

Definition at line 80 of file rttrallocator.hpp.

Constructor(s) / Destructor Details:

◆ RTTRAllocator()

template<typename TAllocator >
RTTRAllocator ( TAllocator & pAllocator)
inlinenoexcept

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 121 of file rttrallocator.hpp.

Method Details:

◆ AllocUnrelated()

template<typename TAllocator >
void * 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()

template<typename TAllocator >
void * 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()

template<typename TAllocator >
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()

template<typename TAllocator >
void RecycleChunk ( void * mem,
size_t size,
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.
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: