From 24b3e5ceba1d91eeb820c6068f4186d92d266ac8 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 6 Jun 2024 23:15:49 +0200 Subject: [PATCH] Library: work out adaptor solution for custom allocator ...turns out to be rather challenging, due to the far reaching requirements * the default case (heap allocation) ''must work out-of-the box'' * optionally a C++ standard conformant `Allocator` can be adapted * which works correct even in case this allocator is ''not a monostate'' * **essential requirement** is to pass an `AllocationCluster` reference directly * need a ''generic extension point'' to adapt to similar elaborate custom schemes __Note__: especially we want to create a direct collaboration between the allocation policy and the underlying allocator to allow support for a dedicate ''realloc operation'' --- src/lib/allocation-cluster.hpp | 3 ++ src/lib/several-builder.hpp | 31 +++++++++----- wiki/thinkPad.ichthyo.mm | 77 +++++++++++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/src/lib/allocation-cluster.hpp b/src/lib/allocation-cluster.hpp index ae76f1336..4ecb4ec98 100644 --- a/src/lib/allocation-cluster.hpp +++ b/src/lib/allocation-cluster.hpp @@ -121,6 +121,9 @@ namespace lib { template Allocator(Allocator const& o) : mother_{o.mother_} { } + template + bool operator== (Allocator const& o) const { return mother_ == o.mother_; } + AllocationCluster* mother_; }; diff --git a/src/lib/several-builder.hpp b/src/lib/several-builder.hpp index ce5d69946..3ee046fd0 100644 --- a/src/lib/several-builder.hpp +++ b/src/lib/several-builder.hpp @@ -62,17 +62,8 @@ namespace lib { namespace {// Allocation management policies - struct HeapOwn - { - void* - realloc (void* data, size_t oldSiz, size_t newSiz) - { - UNIMPLEMENTED ("adjust memory allocation"); ///////////////////////////OOO Problem Objekte verschieben - } - }; - - + template class ALO> class ElementFactory : private ALO @@ -152,6 +143,24 @@ namespace lib { }; + template class ALO> + struct AllocationPolicy + : ElementFactory + { + using Fac = ElementFactory; + using Fac::Fac; + + void* + realloc (void* data, size_t oldSiz, size_t newSiz) + { + UNIMPLEMENTED ("adjust memory allocation"); ///////////////////////////OOO Problem Objekte verschieben + } + }; + + template + using HeapOwn = AllocationPolicy; + + using std::is_trivially_move_constructible_v; using std::is_trivially_destructible_v; using std::has_virtual_destructor_v; @@ -202,7 +211,7 @@ namespace lib { */ template ,class E =I ///< a subclass element element type (relevant when not trivially movable and destructible) - ,class POL =HeapOwn ///< Allocator policy + ,class POL =HeapOwn ///< Allocator policy > class SeveralBuilder : Several diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 00d8c45cb..93061696c 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -81782,19 +81782,31 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + - - + + + + + + + + + + - + + + + + @@ -82191,6 +82203,16 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + @@ -82198,7 +82220,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + @@ -82272,6 +82295,48 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +