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>
Inner Type Index: | |
struct | Node |
Public Field Index: | |
MonoAllocator * | allocator |
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< Node > | stack |
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) |
MonoAllocator* allocator |
The monotonic allocator
Definition at line 70 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 84 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 99 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 89 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 94 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 104 of file rttrallocator.hpp.
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.
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.
lang::SidiListHelper<Node> stack |
List of destructed objects available for recycling.
Definition at line 73 of file rttrallocator.hpp.
|
inline |
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 116 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. |
alignment | The alignment of the object to deallocate. |
dbgTypeInfo | The type information of the object to de-allocate. Available only in debug builds. |