Library: setup adaptor for dynamic adjustments
By means of the extension point, which produces a dedicated policy for use with `AllocationCluster`, it becomes possible to use the specialised API to adjust the latest allocation in the cluster. When this is not actually usable, the policy will fall back on the standard implementation (which is wasteful when applied to `AllocationCluster`, since memory for the obsoleted, smaller blocks not de-allocated then...
This commit is contained in:
parent
7d066a85ee
commit
9709309186
4 changed files with 89 additions and 13 deletions
|
|
@ -330,9 +330,37 @@ namespace lib {
|
|||
struct Policy
|
||||
: AllocationPolicy<I,E,Adapter>
|
||||
{
|
||||
using Base = AllocationPolicy<I,E,Adapter>;
|
||||
using Bucket = typename Base::Bucket;
|
||||
|
||||
Policy (AllocationCluster& clu)
|
||||
: AllocationPolicy<I,E,Adapter> (clu.getAllocator<std::byte>())
|
||||
{ }
|
||||
|
||||
bool
|
||||
canExpand (Bucket* bucket, size_t request)
|
||||
{
|
||||
if (not bucket) return false;
|
||||
size_t currSize = bucket->getAllocSize();
|
||||
size_t delta = request - bucket->buffSiz;
|
||||
return this->mother_->canAdjust (bucket,currSize, currSize+delta);
|
||||
}
|
||||
|
||||
Bucket*
|
||||
realloc (Bucket* bucket, size_t cnt, size_t spread)
|
||||
{
|
||||
size_t request = cnt*spread;
|
||||
REQUIRE (request);
|
||||
if (not canExpand (bucket,request))
|
||||
return Base::realloc (bucket,cnt,spread);
|
||||
|
||||
size_t currSize = bucket->getAllocSize();
|
||||
size_t delta = request - bucket->buffSiz;
|
||||
this->mother_->doAdjust (bucket, currSize, currSize+delta);
|
||||
bucket->buffSiz += delta;
|
||||
ENSURE (bucket->buffSiz == request);
|
||||
return bucket;
|
||||
}
|
||||
};
|
||||
};
|
||||
//
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ namespace lib {
|
|||
|
||||
template<class I, template<typename> class ALO>
|
||||
class ElementFactory
|
||||
: private ALO<std::byte>
|
||||
: protected ALO<std::byte>
|
||||
{
|
||||
using Allo = ALO<std::byte>;
|
||||
using AlloT = std::allocator_traits<Allo>;
|
||||
|
|
@ -261,7 +261,7 @@ namespace lib {
|
|||
ElmAlloT::destroy (elmAllo, elm);
|
||||
}
|
||||
}
|
||||
size_t storageBytes = bucket->buffOffset + bucket->buffSiz;
|
||||
size_t storageBytes = bucket->getAllocSize();
|
||||
std::byte* loc = reinterpret_cast<std::byte*> (bucket);
|
||||
AlloT::deallocate (baseAllocator(), loc, storageBytes);
|
||||
};
|
||||
|
|
@ -277,7 +277,7 @@ namespace lib {
|
|||
|
||||
using Fac::Fac; // pass-through ctor
|
||||
|
||||
bool canExpand(size_t){ return false; }
|
||||
bool canExpand(Bucket*, size_t){ return false; }
|
||||
|
||||
Bucket*
|
||||
realloc (Bucket* data, size_t cnt, size_t spread)
|
||||
|
|
@ -510,7 +510,7 @@ namespace lib {
|
|||
{
|
||||
if (not (Coll::empty()
|
||||
or Coll::hasReserve (requiredSiz, newElms)
|
||||
or POL::canExpand (requiredSiz*newElms)
|
||||
or POL::canExpand (Coll::data_, requiredSiz*newElms)
|
||||
or canDynGrow()))
|
||||
throw err::Invalid{_Fmt{"Several-container is unable to accommodate further element of type %s; "
|
||||
"storage reserve (%d bytes ≙ %d elms) exhausted and unable to move "
|
||||
|
|
|
|||
|
|
@ -131,6 +131,8 @@ namespace lib {
|
|||
size_t buffOffset;
|
||||
|
||||
static constexpr size_t storageOffset = sizeof(ArrayBucket);
|
||||
size_t getAllocSize() const { return buffOffset +buffSiz; }
|
||||
|
||||
|
||||
/** data storage area starts immediately behind the ArrayBucket */
|
||||
std::byte*
|
||||
|
|
@ -147,6 +149,7 @@ namespace lib {
|
|||
ENSURE (storage() <= elm and elm < storage()+buffSiz);
|
||||
return * std::launder (reinterpret_cast<I*> (elm));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}//(End)implementation details
|
||||
|
|
@ -155,7 +158,7 @@ namespace lib {
|
|||
|
||||
/************************************************//**
|
||||
* Abstraction: Fixed array of elements.
|
||||
* Typically the return type is an interface,
|
||||
* Typically the return type is an interface,
|
||||
* and the Implementation wraps some datastructure
|
||||
* holding subclasses.
|
||||
* @note may only be populated through SeveralBuilder
|
||||
|
|
|
|||
|
|
@ -83688,9 +83688,37 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</html></richcontent>
|
||||
</node>
|
||||
<node CREATED="1718412831442" ID="ID_155484703" MODIFIED="1718412860303" TEXT="definiere hier diese Policy als ein class-Template, das von AllocationPolicy erbt"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1718412861728" ID="ID_13977121" MODIFIED="1718412883443" TEXT="damit ist der Rahmen geschaffen, um die realloc()-Funktion zu adaptieren">
|
||||
<linktarget COLOR="#423abb" DESTINATION="ID_13977121" ENDARROW="Default" ENDINCLINATION="-369;15;" ID="Arrow_ID_770351964" SOURCE="ID_1835018318" STARTARROW="None" STARTINCLINATION="371;-12;"/>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1718412861728" ID="ID_13977121" MODIFIED="1718759883360" TEXT="damit ist der Rahmen geschaffen, um die realloc()-Funktion zu adaptieren">
|
||||
<linktarget COLOR="#423abb" DESTINATION="ID_13977121" ENDARROW="Default" ENDINCLINATION="-377;15;" ID="Arrow_ID_770351964" SOURCE="ID_1835018318" STARTARROW="None" STARTINCLINATION="371;-12;"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1718759707337" ID="ID_25176134" MODIFIED="1718759842517" TEXT="canExpand delegieren">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#3a0f69" CREATED="1718759712439" ID="ID_374387139" MODIFIED="1718759803731" TEXT="AllocationCluster braucht mehr Infos">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...ich hab diese Mechanik ganz bewußt <i>janz domm </i>implementiert — also muß praktisch alle Info von oben kommen
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1718759774120" ID="ID_280082650" MODIFIED="1718759784624" TEXT="Bucket* mit übergeben">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#435e98" CREATED="1718759807082" ID="ID_172969715" MODIFIED="1718759840149" TEXT="die Adapter-Policy darf durchaus Insider-Wissen zur lib::Several-Storage haben">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1718759843772" ID="ID_71976653" MODIFIED="1718759873684" TEXT="Verzweigung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1718759853974" ID="ID_400223843" MODIFIED="1718759867069" TEXT="if canExpand ⟹ Anpassung fordern"/>
|
||||
<node CREATED="1718759867692" ID="ID_1902037817" MODIFIED="1718759872175" TEXT="sonst: normales re-alloc"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#581b6b" CREATED="1718412892447" ID="ID_1556718828" MODIFIED="1718412987645" TEXT="ob das man gutgeht....">
|
||||
|
|
@ -83703,6 +83731,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<linktarget COLOR="#2a81b2" DESTINATION="ID_1938493773" ENDARROW="Default" ENDINCLINATION="-141;780;" ID="Arrow_ID_814216426" SOURCE="ID_1342074261" STARTARROW="None" STARTINCLINATION="664;-34;"/>
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#c8b6b6" COLOR="#435e98" CREATED="1718759894633" ID="ID_541911921" MODIFIED="1718759940175" TEXT="unglaublich: es tut!">
|
||||
<icon BUILTIN="smiley-oh"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -84140,14 +84171,28 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1718730232613" ID="ID_194573786" MODIFIED="1718730397838" TEXT="AllocationCluster ankoppeln">
|
||||
<icon BUILTIN="flag-pink"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1718730232613" ID="ID_194573786" MODIFIED="1718759984199" TEXT="AllocationCluster ankoppeln">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1718730253250" ID="ID_361490227" MODIFIED="1718730391736" TEXT="müßte sogar mit der gleichen schon bestehenden front-End-Instanz funktionieren">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1718730287657" ID="ID_1835018318" MODIFIED="1718730388370" TEXT="den gleichen Test-Zyklus mit mehreren re-Allocs machen">
|
||||
<arrowlink COLOR="#423abb" DESTINATION="ID_13977121" ENDARROW="Default" ENDINCLINATION="-369;15;" ID="Arrow_ID_770351964" STARTARROW="None" STARTINCLINATION="371;-12;"/>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1718730287657" ID="ID_1835018318" MODIFIED="1718759949578" TEXT="den gleichen Test-Zyklus mit mehreren re-Allocs machen">
|
||||
<arrowlink COLOR="#423abb" DESTINATION="ID_13977121" ENDARROW="Default" ENDINCLINATION="-377;15;" ID="Arrow_ID_770351964" STARTARROW="None" STARTINCLINATION="371;-12;"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#5b280f" CREATED="1718759951537" HGAP="33" ID="ID_235987237" MODIFIED="1718759979363" TEXT="geht nicht 100% gleich" VSHIFT="9">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...da AllocationCluster eine starke Größenbeschränkgung hat
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<icon BUILTIN="stop-sign"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1718730299524" ID="ID_1847366954" MODIFIED="1718730388370" TEXT="verifizieren, daß die dynamische Anpassung stattgefunden hat">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue