8#ifndef HPP_ALIB_MONOMEM_DETAIL_RECYCLER
9#define HPP_ALIB_MONOMEM_DETAIL_RECYCLER 1
10#if !defined(HPP_ALIB_MONOMEM_DETAIL_HASHTABLEBASE) \
11 && !defined(HPP_ALIB_MONOMEM_LIST)
12# error "ALib sources with ending '.inl' must not be included from outside."
15#if !defined(HPP_ALIB_LANG_TMP) && !defined(ALIB_DOX)
20#if !defined(HPP_ALIB_LANG_SIDILIST)
25# if !defined(HPP_ALIB_LANG_DBGTYPEDEMANGLER)
28# if ALIB_STRINGS && !defined (HPP_ALIB_STRINGS_LOCALSTRING)
33#if !defined (_GLIBCXX_VECTOR) && !defined(_VECTOR_)
37#if !defined (_GLIBCXX_MEMORY) && !defined(_MEMORY_)
42namespace alib {
namespace monomem {
namespace detail {
44#if ALIB_DEBUG_MONOMEM && !defined(ALIB_DOX)
45 void dbgMonoMemRecyclingOutput(
size_t a,
size_t b,
size_t c,
const std::type_info& typeInfo,
size_t d );
58template<
typename TS
idiNode,
typename TList >
87 void recycle( TSidiNode* first, TSidiNode* last )
99 template<
typename TChunk>
103 size_t size=
sizeof(TChunk[1]) *
count;
106 if constexpr(
alignof(TSidiNode) >
alignof(TChunk[1]) )
107 std::align(
alignof(TSidiNode) ,
113 ALIB_DBG(
size_t cntRecycledObjects= 0; )
114 while(size >
sizeof(TSidiNode))
116 recyclables.pushFront(
reinterpret_cast<TSidiNode*
>( mem ) );
118 mem =
reinterpret_cast<char*
>(mem) +
sizeof(TSidiNode);
119 size -=
sizeof (TSidiNode);
125 if( cntRecycledObjects <= 0 )
129 "De-allocated chunk size is smaller than node size.\n"
131 " Size, Count, Alignment: " <<
sizeof(TChunk[1]) <<
" * " <<
count <<
" = "
132 << (
sizeof(TChunk[1]) *
count) <<
" bytes, alignment: "
133 <<
alignof(TChunk[1]) <<
"\n"
135 " Size, Alignment: " <<
sizeof(TSidiNode) <<
" bytes, alignment: " <<
alignof(TSidiNode) <<
"\n"
136 "Note: If this recycler is used with a <monomem::HashTable>, this message may be eliminated\n"
137 " by reserving a reasonable initial bucket size." )
139 ALIB_WARNING( cntRecycledObjects > 0,
"MONOMEM/RECYCLER",
140 "De-allocated chunk size is smaller than node size." )
145 #if ALIB_DEBUG_MONOMEM
146 dbgMonoMemRecyclingOutput(
148 sizeof(TChunk[1]) *
count,
149 sizeof(TChunk[1]) *
count -
sizeof(TSidiNode) * cntRecycledObjects,
150 typeid(TChunk),
count );
178template<
typename TS
idiNode>
216template<
typename TS
idiNode>
223 :
RecyclerPSBase<TSidiNode, lang::SidiListHelper<TSidiNode>&>( sharedRecyclables )
229 :
RecyclerPSBase<TSidiNode, lang::SidiListHelper<TSidiNode>&>( copy )
235 :
RecyclerPSBase<TSidiNode, lang::SidiListHelper<TSidiNode>&>( move )
260template<
typename TS
idiNode>
263#if !defined(ALIB_DOX)
265 void recycle( TSidiNode* )
const {}
266 void recycle( TSidiNode* , TSidiNode* )
const {}
267 constexpr TSidiNode* get()
const {
return nullptr; }
268 constexpr integer count()
const {
return 0; }
269 void disposeRecyclablesIfPrivate()
const {}
270 template<
typename TChunk>
271 void recycleChunk( TChunk*,
size_t )
const {}
#define ALIB_WARNING(...)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
NLocalString< 4096 > NString4K
Type alias name for TLocalString<nchar,4096> .
lang::integer integer
Type alias in namespace alib.
RecyclerPSBase(TList sharedRecyclables)
void recycle(TSidiNode *first, TSidiNode *last)
void recycleChunk(TChunk *chunk, size_t count)
void recycle(TSidiNode *elem)
RecyclerPrivate(const RecyclerPrivate &)
RecyclerPrivate(RecyclerPrivate &&move)
void disposeRecyclablesIfPrivate()
RecyclerShared(lang::SidiListHelper< TSidiNode > &sharedRecyclables)
RecyclerShared(const RecyclerShared ©)
void disposeRecyclablesIfPrivate()
RecyclerShared(RecyclerShared &&move)