45template<
typename TNode>
56template<
typename TNode>
58 TNode* actual = begin;
60 TNode* next= actual->next();
76template<
typename TNode>
78 TNode* begin, TNode* end ) {
79 std::pair<TNode*,integer> result;
83 TNode* next= result.first->next();
91 recyclables.
pushFront( begin, result.first );
102template<
typename TAllocator,
typename TNode>
107 if constexpr ( TAllocator::allowsMemSplit() ) {
108 TNode* newElements= allocator().template AllocArray<TNode>(qty);
109 for(
integer i= qty - 2; i >= 0 ; --i )
110 newElements[i].next( &newElements[i + 1] );
112 recyclables.
pushFront( &newElements[0], &newElements[qty-1] );
114 TNode* start= allocator().template Alloc<TNode>();
116 for(
integer i= 1; i < qty ; ++i ) {
117 end->next( allocator().
template Alloc<TNode>() );
126template<
typename TAllocator,
typename TNode>
130 allocator().Free(elem);
138template<
typename TAllocator,
typename TNode>
140 TNode* actual = begin;
142 TNode* next= actual->next();
144 allocator().Free(actual);
156template<
typename TAllocator,
typename TNode>
157std::pair<TNode*,integer>
disposeListImpl( TAllocator& allocator, TNode* begin, TNode* end ) {
158 std::pair<TNode*,integer> result;
162 TNode* next= result.first->next();
164 allocator().Free(result.first);
179template<
typename TNode,
typename TChunk>
182 size_t size=
sizeof(TChunk[1]) * count;
185 if constexpr(
alignof(TNode) >
alignof(TChunk[1]) ) {
186 mem =
reinterpret_cast<void*
>((size_t(chunk) +
alignof(TNode) - 1) & ~(
alignof(TNode) -1));
187 size-= size_t(
reinterpret_cast<char*
>(mem) -
reinterpret_cast<char*
>(chunk));
191 ALIB_DBG(
size_t cntRecycledObjects= 0; )
192 while(size >
sizeof(TNode)) {
193 recyclables.
pushFront(
reinterpret_cast<TNode*
>( mem ) );
194 mem =
reinterpret_cast<char*
>(mem) +
sizeof(TNode);
195 size -=
sizeof (TNode);
200 if( cntRecycledObjects <= 0 ) {
202 "De-allocated chunk size is smaller than node size.\n"
203 " Chunk object: Type: <{}>\n"
204 " Size, Count, Alignment: {} * {} = {} bytes, alignment: {}\n"
205 " Recyclable Type: <{}>\n"
206 " Size, Alignment: {} bytes, alignment: {}\n"
207 "Note: If this recycler is used with a <containers::HashTable>, this message may be\n"
208 " eliminated by reserving a reasonable initial bucket size.",
209 &
typeid(TChunk),
sizeof(TChunk[1]), count,
sizeof(TChunk[1]) * count,
210 alignof(TChunk[1]), &
typeid(TNode),
sizeof(TNode),
alignof(TNode) )
223template<
typename TAllocator,
typename TNode>
241 :
base( pAllocator ) {}
258 TNode* next= actual->next();
295 :
base::AI().template Alloc<TNode>();
311 std::pair<TNode*, integer>
RecycleList(TNode* begin, TNode* end)
noexcept
332 template<
typename TChunk>
334 if constexpr ( TAllocator::allowsMemSplit() )
337 #if !defined(__MINGW32__)
338 base::AI().FreeArray(chunk, length );
340 base::AI().template FreeArray(chunk, length );
348 template<
typename TChunk>
350 #if !defined(__MINGW32__)
351 base::AI().FreeArray(chunk, length );
353 base::AI().template FreeArray(chunk, length );
366template<
typename TAllocator,
typename TNode>
371 template<
typename TAllocator1,
typename TNode1>
372 friend class RecyclerShared;
417 if( requiredRecyclables > 0 )
428template<
typename TAllocator,
typename TNode>
481 TNode*
Get() {
return !
sr.isEmpty() ?
sr.popFront() :
sr.AI().template Alloc<TNode>(); }
496 std::pair<TNode*, integer>
RecycleList(TNode* begin, TNode* end)
noexcept
514 template<
typename TChunk>
516 if constexpr ( TAllocator::allowsMemSplit() )
519 sr.AI().FreeArray(chunk, length );
526 template<
typename TChunk>
537template<
typename TAllocator,
typename TNode>
551 :
base( pAllocator ) {}
567 {
ALIB_WARNING(
"MONOMEM",
"Requested reservation of recyclables with non-recycling container.") }
587 std::pair<TNode*, integer>
RecycleList( TNode* begin, TNode* end )
noexcept
600 std::pair<TNode*, integer>
DisposeList( TNode* begin, TNode* end )
noexcept
610 template<
typename TChunk>
612 #if !defined(__MINGW32__)
613 base::AI().FreeArray(chunk, length );
615 base::AI().template FreeArray(chunk, length );
623 template<
typename TChunk>
625 #if !defined(__MINGW32__)
626 base::AI().FreeArray(chunk, length );
628 base::AI().template FreeArray(chunk, length );
639template<Recycling TRecycling>
655 template<
typename TAllocator,
typename TNode>
using HookType= void;
660 template<
typename TAllocator,
typename TNode>
using Type = RecyclerShared<TAllocator, TNode>;
661 template<
typename TAllocator,
typename TNode>
using HookType= SharedRecycler<TAllocator, TNode>;
666 template<
typename TAllocator,
typename TNode>
using Type= RecyclerVoid<TAllocator, TNode>;
667 template<
typename TAllocator,
typename TNode>
using HookType= void;
static constexpr bool IsRecycling() noexcept
std::pair< TNode *, integer > RecycleList(TNode *begin, TNode *end) noexcept
void DisposeList(TNode *begin) noexcept
void RecycleList(TNode *begin) noexcept
lang::AllocatorInterface< TAllocator > AI() const noexcept
void Reserve(integer qty)
RecyclerShared(SharedRecycler< TAllocator, TNode > &hook) noexcept
void DisposeChunk(TChunk *chunk, size_t length) noexcept
void DisposeList(TNode *begin, TNode *end) noexcept
~RecyclerShared() noexcept
Destructor.
SharedRecycler< TAllocator, TNode > & sr
The reference to the list of recyclables.
void RecycleChunk(TChunk *chunk, size_t length) noexcept
RecyclerShared(RecyclerShared &&move) noexcept
integer Count() const noexcept
void Reset() noexcept
Does nothing. Shared recyclers can't be reset.
void Recycle(TNode *elem) noexcept
TAllocator & GetAllocator() const noexcept
RecyclerShared(const RecyclerShared ©) noexcept=default
SharedRecycler(TAllocator &pAllocator) noexcept
integer Count() const noexcept
~SharedRecycler() noexcept
Destructor. Deletes all recyclables with the allocator.
lang::SidiListHook< TNode > hookBase
Shortcut to a base class.
void Reset() noexcept
Reset. Deletes all recyclables with the allocator.
void Reserve(integer qty, lang::ValueReference reference)
SharedRecycler() noexcept
Constructor taking no allocator, used with HeapAllocator.
lang::AllocatorMember< TAllocator > allocBase
Shortcut to a base class.
#define ALIB_WARNING(domain,...)
Detail namespace of module ALib Containers.
void reserveImpl(TAllocator &allocator, lang::SidiListHook< TNode > &recyclables, integer qty)
void recycleListImpl(lang::SidiListHook< TNode > &recyclables, TNode *begin)
void disposeListImpl(TAllocator &allocator, TNode *begin)
void recycleImpl(lang::SidiListHook< TNode > &recyclables, TNode *elem)
void recycleChunkImpl(lang::SidiListHook< TNode > &recyclables, TChunk *chunk, size_t count)
void disposeImpl(TAllocator &allocator, TNode *elem)
@ Private
< Denotes private recycling. This is usaully the default value.
@ None
< Denotes that no recycling should be performed.
@ Shared
< Denotes shared recycling.
ValueReference
Denotes if a value is interpreted as an absolute or relative number.
@ Absolute
Referring to an absolute value.
lang::integer integer
Type alias in namespace alib.
containers::Recycling Recycling
Type alias in namespace alib.
void Reset() noexcept
Resets this recycler. Frees all recyclables with the allocator.
void DisposeList(TNode *begin, TNode *end) noexcept
void DisposeList(TNode *begin) noexcept
lang::AllocatorMember< TAllocator > base
The base type.
integer Count() const noexcept
void DisposeChunk(TChunk *chunk, size_t length) noexcept
std::pair< TNode *, integer > RecycleList(TNode *begin, TNode *end) noexcept
RecyclerPrivate() noexcept=default
Parameterless constructor. Used with type HeapAllocator.
void Recycle(TNode *elem) noexcept
lang::AllocatorInterface< TAllocator > AI() const noexcept
void RecycleChunk(TChunk *chunk, size_t length) noexcept
~RecyclerPrivate() noexcept
Destructor. Frees all recyclables with the allocator.
TAllocator & GetAllocator() const noexcept
lang::SidiListHook< TNode > recyclables
The list of recyclables.
void Reserve(integer qty) noexcept
void RecycleList(TNode *begin) noexcept
RecyclerPrivate(RecyclerPrivate &&move) noexcept
static constexpr bool IsRecycling() noexcept
RecyclerPrivate(const RecyclerPrivate ©) noexcept
lang::AllocatorMember< TAllocator > base
The base type.
std::pair< TNode *, integer > RecycleList(TNode *begin, TNode *end) noexcept
void DisposeList(TNode *begin) noexcept
void RecycleList(TNode *begin) noexcept
std::pair< TNode *, integer > DisposeList(TNode *begin, TNode *end) noexcept
RecyclerVoid()
Parameterless constructor. Used with type HeapAllocator.
void Reset() noexcept
Does nothing. Shared recyclers can't be reset.
void DisposeChunk(TChunk *chunk, size_t length) noexcept
constexpr void RecycleChunk(TChunk *chunk, size_t length) noexcept
void Recycle(TNode *elem) noexcept
void Reserve(integer) noexcept
Does nothing. In debug-compilations a warning is raised.
RecyclerVoid(TAllocator &pAllocator) noexcept
constexpr integer Count() const noexcept
static constexpr bool IsRecycling() noexcept
void Type
The type chosen.
void HookType
The hook type. Only used with shared recycling, otherwise void.
AllocatorInterface< TAllocator > AI() const noexcept
TAllocator & GetAllocator() const noexcept
void reset() noexcept
Resets this list to zero elements.
TNode * first() const noexcept
void pushFront(TElement *elem) noexcept
SidiNodeBase< TNode > TNode
integer count(TNode *end=nullptr) const noexcept
void next(SidiNodeBase *p)