8#ifndef HPP_ALIB_MONOMEM_UTIL_RTTRALLOCATOR
9#define HPP_ALIB_MONOMEM_UTIL_RTTRALLOCATOR
11#if ALIB_DEBUG && !defined(HPP_ALIB_LANG_DBGTYPEDEMANGLER)
15#if !defined(HPP_ALIB_MONOMEM_MONOALLOCATOR)
19#if !defined(HPP_ALIB_LANG_SIDILIST)
24# if ALIB_STRINGS && !defined (HPP_ALIB_STRINGS_LOCALSTRING)
29#if !defined (HPP_ALIB_MONOMEM_MONOMEM)
33namespace alib {
namespace monomem {
119 DBG_MONOMEM_FILE_DOMAIN(
"UTIL/RTTA")
140 char*
Get(
size_t size,
size_t alignment,
const type_info& dbgTypeInfo);
142 char*
Get(
size_t size,
size_t alignment
ALIB_DBG(,
const std::type_info& dbgTypeInfo) )
152 DBG_MONOMEM_INFO(
"Object type detected : {!Q<>}", dbgTypeInfo )
154 "MONOMEM/RTTRA",
"Struct RTTRAllocator can not be used to recycle types with an alignment "
155 "smaller than ",
alignof(
Node) )
160 if( !
stack.isEmpty() )
162 DBG_MONOMEM_VERBOSE(
"Recycling object. Type: {!Q<>}", dbgTypeInfo )
164 return reinterpret_cast<char*
>(
stack.popFront() );
172 "A different object was requested for allocation!\n"
175 "Note: This allocator may not be efficient when used.\n"
176 " If this is a use case using a 'std' library container, this message indicates\n"
177 " that a RTTRAllocator was shared between different container instantiations.\n"
178 " If this is not the case, than an 'unusual' implementation of such C++ library may\n"
179 " prevent this concept from working. See ALib manual for further information" )
182 "A different object was requested for allocation!\n" )
186 DBG_MONOMEM_WARNING(
"Allocating a different object type {!Q<>}\n Note: This object can not be recycled.", dbgTypeInfo )
188 :
static_cast<char*
>(std::malloc( size ));
192 DBG_MONOMEM_VERBOSE(
"Allocating object. Type: {!Q<>}", dbgTypeInfo )
196 "Struct RTTRAllocator can not be used to allocate types with an alignment "
197 "greater than 'alignof(std::max_align_t)'." )
199 : static_cast<
char*>(std::malloc( size ));
213 char*
AllocUnrelated(
size_t size,
size_t alignment,
const type_info& dbgTypeInfo);
218 DBG_MONOMEM_VERBOSE(
"Allocating other. Type: {!Q<>}", dbgTypeInfo )
220 :
static_cast<char*
>(std::malloc( size ));
243 void Recycle(
void* mem,
size_t size,
size_t alignment,
const type_info& dbgTypeInfo );
245 void Recycle(
void* mem,
size_t size,
size_t alignment
ALIB_DBG(,
const std::type_info& dbgTypeInfo) )
250 stack.pushFront(
reinterpret_cast<Node*
>( mem ) );
252 DBG_MONOMEM_VERBOSE(
"Stacking object. Type: {!Q<>}", dbgTypeInfo )
263 "De-allocation prior to a first object allocation needed to detect recyclable type!\n"
265 "Note: This allocator may not be efficient when used.\n"
266 " If this is a use case using a 'std' library container, this message indicates\n"
267 " an 'unusual' implementation of such C++ standard library." )
270 "De-allocation prior to a first object allocation needed to detect recyclable type!" )
279 "A different object for was requested for de-allocoation!\n"
282 "Note: This allocator may not be efficient when used.\n"
283 " If this is a use case using a 'std' library container, this message indicates\n"
284 " that a RTTRAllocator was shared between different container instantiations.\n"
285 " If this is not the case, than an 'unusual' implementation of such C++ library may\n"
286 " prevent this concept from working. See ALib manual for further information" )
289 "A different object for was requested for de-allocoation!" )
315 void RecycleChunk(
char* mem,
size_t size,
size_t alignment,
const type_info& dbgTypeInfo );
317 void RecycleChunk(
void* mem,
size_t size,
size_t alignment
ALIB_DBG(,
const std::type_info& dbgTypeInfo) )
332 "De-allocation prior to a first object allocation needed to detect recyclable type!\n"
334 "Note: If this recycler is used with a 'std' library container, this either\n"
335 " indicates an 'unusual' implementation of such C++ standard library,\n"
336 " or a manual shrink of the capacity without any prior object insertion." )
339 "De-allocation prior to a first object allocation needed to detect recyclable type!" )
354 ALIB_DBG(
size_t cntStackedObjects= 0; )
357 stack.pushFront(
reinterpret_cast<Node*
>( mem ) );
367 "De-allocated chunk's size is smaller than detected object size.\n"
369 " Size: " << origSize <<
" bytes, alignment: " << alignment <<
"\n"
372 "Note: If this recycler is used with a <std::unordered_map> or <std::unordered_set>,\n"
373 " this message may be eliminated by reserving a reasonable initial bucket size." )
376 "De-allocated chunk's size is smaller than detected object size." )
380 DBG_MONOMEM_INFO(
"Stacking {} objects from de-allocated memory of size {} (lost {} bytes). Deallocated type: {!Q<>}.",
ALIB_API const char * Get()
ALIB_FORCE_INLINE char * Alloc(size_t size, size_t alignment)
#define ALIB_WARNINGS_RESTORE
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
#define ALIB_ASSERT_WARNING(cond,...)
NLocalString< 1024 > NString1K
Type alias name for TLocalString<nchar,1024> .
bool dbgWarnDeallocationPriorToAllocation
const std::type_info * dbgDetectedObjectTypeInfo
char * AllocUnrelated(size_t size, size_t alignment, const type_info &dbgTypeInfo)
RTTRAllocator(MonoAllocator *pAllocator)
bool dbgWarnDifferentObjectTypeDealloc
size_t detectedObjectAlignment
char * Get(size_t size, size_t alignment, const type_info &dbgTypeInfo)
bool dbgWarnDifferentObjectTypeAlloc
MonoAllocator * allocator
void RecycleChunk(char *mem, size_t size, size_t alignment, const type_info &dbgTypeInfo)
void Recycle(void *mem, size_t size, size_t alignment, const type_info &dbgTypeInfo)
lang::SidiListHelper< Node > stack
bool dbgWarnRecycleChunkPriorToAllocation
size_t detectedObjectSize