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.
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.
TAllocator | The allocator type, as prototyped with Allocator. |
Definition at line 69 of file rttrallocator.hpp.
#include <rttrallocator.hpp>
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< Node > | stack |
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. | |
using allocBase = AllocatorMember<TAllocator> |
The allocator type that TAllocator specifies.
Definition at line 72 of file rttrallocator.hpp.
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.
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.
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.
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.
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.
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.
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.
SidiListHook<Node> stack |
List of destructed objects available for recycling.
Definition at line 80 of file rttrallocator.hpp.
|
inlinenoexcept |
Constructor taking the monotonic allocator.
If nullptr
is given, this recycler uses std::malloc
and std::free
for memory allocation and de-allocation.
pAllocator | The monotonic allocator. If nullptr is given, still recycling of node objects is performed. |
Definition at line 121 of file rttrallocator.hpp.
|
inline |
Allocates memory for a type different to the dedicated, detected object type.
size | The requested size. |
alignment | The requested alignment |
dbgTypeInfo | The type information of the object to allocate. Available only in debug-builds. |
|
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.
size | The requested size. |
alignment | The requested alignment |
dbgTypeInfo | The type information of the object to allocate. Available only in debug-builds. |
|
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.
mem | The object to deallocate. |
size | The size of the object to deallocate. |
alignment | The alignment of the object to deallocate. |
dbgTypeInfo | The type information of the object to de-allocate. Available only in debug-builds. |
|
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.
mem | The object to deallocate. |
size | The size of the object to deallocate. |
dbgTypeInfo | The type information of the object to de-allocate. Available only in debug-builds. |