From e4f91ecb4d7019cca17db2b7cdaf0d1f1ffc7511 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 27 May 2024 23:35:59 +0200 Subject: [PATCH] Library: document usage of AllocationCluster for STL containers - basically works out-of-the-box now - the hard wired fixed Extent size is a serious limitation - however, this is not the intended primary use, rather complementary --- src/lib/scoped-holder.hpp | 1 - tests/library/allocation-cluster-test.cpp | 56 ++++++- wiki/thinkPad.ichthyo.mm | 175 +++++++++++++++++----- 3 files changed, 184 insertions(+), 48 deletions(-) diff --git a/src/lib/scoped-holder.hpp b/src/lib/scoped-holder.hpp index 15a41a148..745870c68 100644 --- a/src/lib/scoped-holder.hpp +++ b/src/lib/scoped-holder.hpp @@ -50,7 +50,6 @@ ** ** @see scoped-holder-test.cpp ** @see scoped-holder-transfer.hpp use in std::vector - ** @see AllocationCluster usage example ** @see scoped-ptrvect.hpp simple pointer-holding collection */ diff --git a/tests/library/allocation-cluster-test.cpp b/tests/library/allocation-cluster-test.cpp index 030b5ca1f..65f28c5b8 100644 --- a/tests/library/allocation-cluster-test.cpp +++ b/tests/library/allocation-cluster-test.cpp @@ -30,13 +30,15 @@ #include "lib/test/test-helper.hpp" #include "lib/allocation-cluster.hpp" #include "lib/test/diagnostic-output.hpp"/////////////////TODO +#include "lib/format-util.hpp"/////////////TODO #include "lib/iter-explorer.hpp" #include "lib/util.hpp" -#include -#include -#include #include +#include +#include +#include +#include using ::Test; using lib::explore; @@ -129,6 +131,11 @@ namespace test { invoker[rand() % NUM_TYPES] (clu, uchar(i)); } + inline uint + sum (uint n) ///< sum of integers 1...N + { + return n*(n+1) / 2; + } } @@ -369,13 +376,50 @@ namespace test { - /** @test TODO demonstrate use as Standard-Allocator - * @todo WIP 5/24 🔁 define ⟶ implement + template + using Allo = AllocationCluster::Allocator; + + /** @test demonstrate use as Standard-Allocator + * - define a vector, string and set to use the AllocationCluster as backend + * - fill the vector with numbers and the set with random strings + * @note the extent size (hard coded as of 5/24) imposes a serious limitation + * regarding usable data structures; e.g. the std::deque immediately attempts + * to allocate a node buffer with >500 bytes, which is not supported by + * the current (rather simplistic) storage manager in AllocationCluster. */ void use_as_Allocator() { - UNIMPLEMENTED ("Clusterfuck"); + using VecI = std::vector>; + using Strg = std::basic_string, Allo>; + using SetS = std::set, Allo>; + + AllocationCluster clu; + CHECK (clu.numExtents() == 0); + + VecI veci{clu.getAllocator()}; + + // Since vector needs a contiguous allocation, + // the maximum number of elements is limited by the Extent size (256 bytes - 2*sizeof(void*)) + // Moreover, the vector grows its capacity; AllocationCluster does not support re-allocation, + // and thus the initial smaller memory chunks will just be abandoned. + const uint MAX = 64; + + for (uint i=1; i<=MAX; ++i) + veci.push_back(i); + CHECK (clu.numExtents() == 2); + CHECK (veci.capacity() == 64); + + // fill a set with random strings... + SetS sets{clu.getAllocator()}; + + for (uint i=0; i()); + CHECK (sets.size() > 0.9 * NUM_OBJECTS); + CHECK (clu.numExtents() > 200); + + // verify the data in the first allocation is intact + CHECK (explore(veci).resultSum() == sum(64)); } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index bf2057bae..828610520 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -81606,7 +81606,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -81621,18 +81621,42 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - @@ -81890,11 +81914,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - - - - + + + + + @@ -81907,21 +81931,24 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + - + + + - - + + - - + + @@ -81937,15 +81964,37 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + - - + + + + + + + + - - + + + + + + + +

+ naja... ehrlich gesagt, +

+

+ es gibt noch gar keine Verwendungen +

+ + +
+ +
@@ -82245,23 +82294,25 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - - - - - - - - + + + + + + + + + + + - - + + - - + + @@ -82302,8 +82353,50 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -82473,9 +82566,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + - +