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''
This commit is contained in:
parent
c5d1a7d0df
commit
24b3e5ceba
3 changed files with 94 additions and 17 deletions
|
|
@ -121,6 +121,9 @@ namespace lib {
|
|||
template<typename T>
|
||||
Allocator(Allocator<T> const& o) : mother_{o.mother_} { }
|
||||
|
||||
template<typename T>
|
||||
bool operator== (Allocator<T> const& o) const { return mother_ == o.mother_; }
|
||||
|
||||
AllocationCluster* mother_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 I, template<typename> class ALO>
|
||||
class ElementFactory
|
||||
: private ALO<std::byte>
|
||||
|
|
@ -152,6 +143,24 @@ namespace lib {
|
|||
};
|
||||
|
||||
|
||||
template<class I, template<typename> class ALO>
|
||||
struct AllocationPolicy
|
||||
: ElementFactory<I, ALO>
|
||||
{
|
||||
using Fac = ElementFactory<I, ALO>;
|
||||
using Fac::Fac;
|
||||
|
||||
void*
|
||||
realloc (void* data, size_t oldSiz, size_t newSiz)
|
||||
{
|
||||
UNIMPLEMENTED ("adjust memory allocation"); ///////////////////////////OOO Problem Objekte verschieben
|
||||
}
|
||||
};
|
||||
|
||||
template<class I>
|
||||
using HeapOwn = AllocationPolicy<I, std::allocator>;
|
||||
|
||||
|
||||
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 I ///< Interface or base type visible on resulting Several<I>
|
||||
,class E =I ///< a subclass element element type (relevant when not trivially movable and destructible)
|
||||
,class POL =HeapOwn ///< Allocator policy
|
||||
,class POL =HeapOwn<I> ///< Allocator policy
|
||||
>
|
||||
class SeveralBuilder
|
||||
: Several<I>
|
||||
|
|
|
|||
|
|
@ -81782,19 +81782,31 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716901650386" ID="ID_636334267" MODIFIED="1716903157046" TEXT="Array-Repräsentation">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1716901650386" ID="ID_636334267" MODIFIED="1717723386278" TEXT="Array-Repräsentation">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1716903158346" ID="ID_1317174249" MODIFIED="1716907525705" TEXT="im Container(≙Handle): (size, start)"/>
|
||||
<node CREATED="1716903185047" ID="ID_1036525121" MODIFIED="1716903198769" TEXT="im ArrayBucket">
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716903201165" ID="ID_443006340" MODIFIED="1716907430046" TEXT="Manager">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#5b280f" CREATED="1716903201165" ID="ID_443006340" MODIFIED="1717723256773" TEXT="Manager">
|
||||
<icon BUILTIN="button_cancel"/>
|
||||
<node CREATED="1716904170396" ID="ID_1253230124" MODIFIED="1716904183622" TEXT="das ist eine trickreich belegte Union"/>
|
||||
<node CREATED="1716904184162" ID="ID_990254994" MODIFIED="1716904195917" TEXT="kann als »unmanaged« markiert werden"/>
|
||||
<node CREATED="1716904197917" ID="ID_1121578813" MODIFIED="1716904215226" TEXT="nullptr ⟹ std::allocator verwenden"/>
|
||||
<node CREATED="1716904231812" ID="ID_1732387735" MODIFIED="1716904732789" TEXT="sonst: pointer auf eine delete-Function void(void*, bytes)"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#c8c0b6" COLOR="#435e98" CREATED="1717723266104" ID="ID_732548333" MODIFIED="1717723351726" TEXT="Deleter">
|
||||
<node CREATED="1717723276746" ID="ID_926335468" MODIFIED="1717723288188" TEXT="pointer auf eine Deleter-Funktion"/>
|
||||
<node CREATED="1716904197917" ID="ID_656688517" MODIFIED="1717723309004" TEXT="nullptr ⟹ »unmanaged«">
|
||||
<node CREATED="1717723318324" HGAP="24" ID="ID_182387447" MODIFIED="1717723344344" TEXT="heißt: Speicher einfach fallen lassen" VSHIFT="4">
|
||||
<icon BUILTIN="info"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1716904075721" ID="ID_1409827773" MODIFIED="1716904079637" TEXT="spread"/>
|
||||
<node CREATED="1716904088399" ID="ID_1134374495" MODIFIED="1716904091035" TEXT="storage"/>
|
||||
<node CREATED="1716904088399" ID="ID_1134374495" MODIFIED="1716904091035" TEXT="storage">
|
||||
<node CREATED="1717723358455" HGAP="23" ID="ID_960040668" MODIFIED="1717723379742" TEXT="Platzhalter für den Anfang der uninitialised-storage" VSHIFT="6">
|
||||
<icon BUILTIN="info"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -82191,6 +82203,16 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1717542814132" ID="ID_1446789676" MODIFIED="1717542831827" TEXT="komplett vom Allokator trennen!">
|
||||
<icon BUILTIN="yes"/>
|
||||
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1717722066869" HGAP="45" ID="ID_1393193544" MODIFIED="1717722085492" TEXT="will nicht recht gelingen" VSHIFT="-7">
|
||||
<icon BUILTIN="smiley-angry"/>
|
||||
<node CREATED="1717722088033" ID="ID_1385471831" MODIFIED="1717722110690" TEXT="ich will verschiedene Belange zugleich abdecken"/>
|
||||
<node CREATED="1717722112617" ID="ID_129641323" MODIFIED="1717722144214" TEXT="einerseits habe ich ein realloc() rein auf Basis von byte-Größen"/>
|
||||
<node CREATED="1717722145066" ID="ID_869042761" MODIFIED="1717722165412" TEXT="andererseits habe ich sogar das ArrayBucket auf den Basistyp typisiert"/>
|
||||
<node CREATED="1717722171998" ID="ID_970346456" MODIFIED="1717722203508" TEXT="und folglich ⟹ auch die ElementFactory muß den Basistyp kennen"/>
|
||||
<node CREATED="1717722314467" ID="ID_620857317" MODIFIED="1717722345375" TEXT="und drittens möchte ich rein auf Basis des Allokators die Policy schwenken können">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1717542588800" ID="ID_1355622101" MODIFIED="1717542604293" TEXT="Prädikate">
|
||||
<node CREATED="1717542623647" ID="ID_749518164" MODIFIED="1717542633699" TEXT="canDestroy<TY>"/>
|
||||
|
|
@ -82198,7 +82220,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node CREATED="1717542702415" ID="ID_1473880478" MODIFIED="1717545646724" TEXT="canAdjust ⟵ wild-move-Flag"/>
|
||||
</node>
|
||||
<node CREATED="1717543060128" ID="ID_1973537913" MODIFIED="1717543071098" TEXT="Handler">
|
||||
<node CREATED="1717543072032" ID="ID_1791379026" MODIFIED="1717543076568" TEXT="getDeleter()">
|
||||
<node CREATED="1717543072032" ID="ID_1791379026" MODIFIED="1717723687678" TEXT="getDeleter()">
|
||||
<arrowlink COLOR="#e1073d" DESTINATION="ID_1412900866" ENDARROW="Default" ENDINCLINATION="344;0;" ID="Arrow_ID_453255140" STARTARROW="Default" STARTINCLINATION="344;0;"/>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1717546372010" ID="ID_231852526" MODIFIED="1717596420967" TEXT="klären: wie wird er konkret verwendet?">
|
||||
<icon BUILTIN="help"/>
|
||||
<node CREATED="1717546388726" ID="ID_1089262988" MODIFIED="1717546407495" TEXT="muß einen Pointer auf ein Trampolin speichern können"/>
|
||||
|
|
@ -82272,6 +82295,48 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1717723412216" ID="ID_1483275702" MODIFIED="1717723419487" TEXT="Allokator flexibel einbinden">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1717723422166" ID="ID_1525424957" MODIFIED="1717723517420" TEXT="Anforderungen">
|
||||
<icon BUILTIN="yes"/>
|
||||
<node CREATED="1717723426670" ID="ID_1964183784" MODIFIED="1717723456378" TEXT="Standardfall: Heap-Allokation �� muß automatisch funktionieren">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
<node CREATED="1717723464433" ID="ID_108739270" MODIFIED="1717723551804" TEXT="man kann einen beliebigen C++-Standardkonformen Allokator verwenden">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
<node CREATED="1717723483198" ID="ID_862009636" MODIFIED="1717723551804" TEXT="man kann eine AllocationCluster-Instanz direkt (via Builder) durchgeben">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
<node CREATED="1717723530936" ID="ID_690313592" MODIFIED="1717723558000" TEXT="Erweiterungspunkt für beliebiges anderes Allocator-Schema schaffen">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1717723564508" ID="ID_16935134" MODIFIED="1717723623192" TEXT="verwende eine AllocationPolicy">
|
||||
<icon BUILTIN="idea"/>
|
||||
<node CREATED="1717723580796" ID="ID_453265164" MODIFIED="1717723597659" TEXT="der Builder erbt von dieser (Policy Mix-In)"/>
|
||||
<node CREATED="1717723599686" ID="ID_1353907596" MODIFIED="1717723615688" TEXT="sie mischt ihrerseits eine ElementFactory ein"/>
|
||||
<node CREATED="1717723625139" ID="ID_1954915705" MODIFIED="1717723635781" TEXT="Adapter-Methoden">
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1717723636675" ID="ID_1612255322" MODIFIED="1717723717303" TEXT="realloc">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1717723720004" ID="ID_456348135" MODIFIED="1717723723226" TEXT="Anforderungen">
|
||||
<node CREATED="1717723724203" ID="ID_54813391" MODIFIED="1717723733914" TEXT="entscheidet intelligent was zu tun ist"/>
|
||||
<node CREATED="1717723734527" ID="ID_184980735" MODIFIED="1717723746074" TEXT="unterstützt auch die normale (initiale) Allokation"/>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1717723747298" ID="ID_1111696667" MODIFIED="1717723776089" TEXT="kann mit dem unterliegenden Allokator eine Spezialbehandlung abstimmen">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1717723649872" ID="ID_1412900866" MODIFIED="1717723682406" TEXT="Deleter einbinden?">
|
||||
<linktarget COLOR="#e1073d" DESTINATION="ID_1412900866" ENDARROW="Default" ENDINCLINATION="344;0;" ID="Arrow_ID_453255140" SOURCE="ID_1791379026" STARTARROW="Default" STARTINCLINATION="344;0;"/>
|
||||
<icon BUILTIN="help"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1717723703235" ID="ID_239148471" MODIFIED="1717723715407" TEXT="Objekt platzieren mit durchgereichten ctor-Argumenten">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1716914864769" ID="ID_966642586" MODIFIED="1716914906125" TEXT="Builder-Operationen">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1717634297656" ID="ID_330412196" MODIFIED="1717688579115" TEXT="Move-builder und Container per Slice ausgeben">
|
||||
|
|
|
|||
Loading…
Reference in a new issue