diff --git a/src/lib/allocation-cluster.cpp b/src/lib/allocation-cluster.cpp index f330d3c95..bf9e686b4 100644 --- a/src/lib/allocation-cluster.cpp +++ b/src/lib/allocation-cluster.cpp @@ -53,24 +53,8 @@ namespace lib { const size_t EXTENT_SIZ = 256; const size_t OVERHEAD = 2 * sizeof(void*); const size_t STORAGE_SIZ = EXTENT_SIZ - OVERHEAD; - - using HeapAlloc = std::allocator; - using Alloc = std::allocator_traits; - HeapAlloc heap; - void* - allocate (size_t bytes) ////////////////////////OOO obsolete ... find a way to relocate this as custom allocator within LinkedElements!!! - { - return Alloc::allocate (heap, bytes); - } - - void - destroy (void* storage) - { - Alloc::destroy (heap, static_cast (storage)); - } - /** * Special allocator-policy for lib::LinkedElements * - does not allow to allocate new elements @@ -86,7 +70,7 @@ namespace lib { */ template void - destroy (X* elm) + dispose (X* elm) { REQUIRE (elm); elm->~X(); diff --git a/src/lib/allocator-handle.hpp b/src/lib/allocator-handle.hpp index 46b900c51..fe9df790f 100644 --- a/src/lib/allocator-handle.hpp +++ b/src/lib/allocator-handle.hpp @@ -64,7 +64,7 @@ namespace lib { - namespace allo { /** Concepts and Adapter for custom memory management */ + namespace allo {///< Concepts and Adaptors for custom memory management /////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1366 : define Allocator Concepts here /// TODO the following Concepts can be expected here (with C++20) @@ -110,16 +110,16 @@ namespace lib { template typename ALOT::pointer - construct (typename ALOT::alocator_type& allo, ARGS&& ...args) + construct (typename ALOT::allocator_type& allo, ARGS&& ...args) { - auto loc = ALOT::allocate (allocator_, 1); - ALOT::construct (allocator_, loc, std::forward(args)...); + auto loc = ALOT::allocate (allo, 1); + ALOT::construct (allo, loc, std::forward(args)...); return loc; } - template + template void - destroy (typename ALOT::alocator_type& allo, typename ALOT::pointer elm) + destroy (typename ALOT::allocator_type& allo, typename ALOT::pointer elm) { ALOT::destroy (allo, elm); ALOT::deallocate (allo, elm, 1); diff --git a/src/lib/linked-elements.hpp b/src/lib/linked-elements.hpp index de7a6459c..9cd36c5cf 100644 --- a/src/lib/linked-elements.hpp +++ b/src/lib/linked-elements.hpp @@ -1,5 +1,5 @@ /* - LINKED-ELEMENTS.hpp - configurable intrusive single linked list template + LINKED-ELEMENTS.hpp - configurable intrusive single linked list template Copyright (C) Lumiera.org 2012, Hermann Vosseler @@ -39,8 +39,8 @@ ** ** @note this linked list container is _intrusive_ and thus needs the help ** of the element type, which must *provide a pointer member* `next`. - ** Consequently, each such node element can't be member in - ** multiple collections at the same time + ** Consequently, each such node element can not be member in + ** several collections at the same time (unless they share all elements) ** @note as usual, any iterator relies on the continued existence and ** unaltered state of the container. There is no sanity check. ** @warning this container is deliberately not threadsafe @@ -50,7 +50,7 @@ ** this node element when going out of scope. ** ** @see LinkedElements_test - ** @see llist.h + ** @see allocator-handle.hpp ** @see ScopedCollection ** @see itertools.hpp */ @@ -80,38 +80,24 @@ namespace lib { namespace linked_elements { ///< allocation policies for the LinkedElements list container /** - * Policy for LinkedElements: taking ownership - * and possibly creating heap allocated Nodes + * Policy for LinkedElements: taking ownership and + * possibly creating new Nodes through a custom allocator. + * @tparam ALO a C++ standard conformant allocator * @note is util::MoveOnly to enforce ownership * on behalf of LinkedElements */ - struct OwningHeapAllocated - : util::MoveOnly + template + struct OwningAllocated + : lib::allo::StdFactory + , util::MoveOnly { - typedef void* CustomAllocator; + using lib::allo::StdFactory::StdFactory; - /** this policy discards elements - * by deallocating them from heap - */ - template - void - destroy (X* elm) - { - delete elm; - } - - - /** this policy creates new elements - * simply by heap allocation */ - template - TY& - create (ARGS&& ...args) - { - return *new TY (std::forward (args)...); - } + using CustomAllocator = ALO; }; - + template + using OwningHeapAllocated = OwningAllocated>; @@ -120,7 +106,7 @@ namespace lib { /** * Policy for LinkedElements: never create or destroy * any elements, only allow to add already existing nodes. - * @note any added node needs to provide a \c next pointer + * @note any added node needs to provide a `next` pointer * field, which is used ("intrusively") for managing * the list datastructure. But besides that, the * node element won't be altered or discarded @@ -133,8 +119,8 @@ namespace lib { /** this policy doesn't take ownership * and thus never discards anything */ - void - destroy (void*) + void + dispose (void*) { /* does nothing */ } @@ -181,18 +167,18 @@ namespace lib { * within the cluster will be bulk de-allocated * when the cluster as such goes out of scope. */ - void - destroy (void*) + void + dispose (void*) { /* does nothing */ } template - TY& + TY* create (ARGS&& ...args) { - return cluster_.create (std::forward (args)...); + return & cluster_.create (std::forward (args)...); } }; @@ -222,7 +208,7 @@ namespace lib { */ template < class N ///< node class or Base/Interface class for nodes - , class ALO = linked_elements::OwningHeapAllocated + , class ALO = linked_elements::OwningHeapAllocated > class LinkedElements : ALO @@ -233,7 +219,7 @@ namespace lib { public: ~LinkedElements() - { + { clear(); } @@ -290,7 +276,7 @@ namespace lib { N* elm = head_; head_ = head_->next; try { - ALO::destroy(elm); + ALO::dispose (elm); } ERROR_LOG_AND_IGNORE (progress, "Clean-up of element in LinkedElements list") } @@ -332,7 +318,7 @@ namespace lib { TY& emplace (ARGS&& ...args) { - return push (ALO::template create (std::forward (args)...)); + return push (* ALO::template create (std::forward (args)...)); } diff --git a/tests/library/linked-elements-test.cpp b/tests/library/linked-elements-test.cpp index bc6f6fd93..4eb8a7f19 100644 --- a/tests/library/linked-elements-test.cpp +++ b/tests/library/linked-elements-test.cpp @@ -28,6 +28,7 @@ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" +#include "lib/test/diagnostic-output.hpp"/////////////TODO #include "lib/util.hpp" #include "lib/allocation-cluster.hpp" @@ -486,7 +487,7 @@ namespace test{ elements.emplace> (4,5); elements.emplace> (7,8,9); - const size_t EXPECT = sizeof(Num<1>) + sizeof(Num<3>) + sizeof(Num<6>); + const size_t EXPECT = sizeof(Num<1>) + sizeof(Num<3>) + sizeof(Num<6>) + 3*2*sizeof(void*); CHECK (EXPECT == allocator.numBytes()); CHECK (sum(9) == Dummy::checksum()); @@ -500,7 +501,9 @@ namespace test{ CHECK (sum(9) == Dummy::checksum()); // note: elements won't be discarded unless // the AllocationCluster goes out of scope +SHOW_EXPR(Dummy::checksum()) } +SHOW_EXPR(Dummy::checksum()) CHECK (0 == Dummy::checksum()); } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index bc3f8bca3..95a3bb10f 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -64988,8 +64988,7 @@ die Grundbegriffe sind für Concepts reserviert

- - + @@ -65037,8 +65036,7 @@ - - + @@ -65049,8 +65047,7 @@ Factory wird das zentrale Schnittstellen-Concept zur restlichen Applikation

- - +
@@ -65181,8 +65178,8 @@ - - + +