Library: integrate storage-management logic
Parts of this logic were first coded down in the `realloc` template method, where it did not really belong; thus reintegrate similar logic one level above, in the SeveralBuilder::adjustStorage(). Moreover, for performance reasons, always start with an initial chunk, similar to what `std::vector` does...
This commit is contained in:
parent
e99f4d531b
commit
54bd568714
2 changed files with 149 additions and 67 deletions
|
|
@ -67,6 +67,12 @@ namespace lib {
|
|||
|
||||
namespace {// Allocation management policies
|
||||
|
||||
/** number of storage slots to open initially;
|
||||
* starting with an over-allocation similar to `std::vector`
|
||||
*/
|
||||
const uint INITIAL_ELM_CNT = 10;
|
||||
|
||||
|
||||
using util::max;
|
||||
using util::min;
|
||||
using util::_Fmt;
|
||||
|
|
@ -357,22 +363,72 @@ namespace lib {
|
|||
}
|
||||
|
||||
private:
|
||||
template<class IT>
|
||||
void
|
||||
emplaceCopy (IT& dataSrc)
|
||||
{
|
||||
using Val = std::remove_cv_t<typename IT::value_type>;
|
||||
emplaceElm<Val> (*dataSrc);
|
||||
}
|
||||
|
||||
template<class TY, typename...ARGS>
|
||||
void
|
||||
emplaceElm (ARGS&& ...args)
|
||||
{
|
||||
if (not handling_.template canDestroy<TY>())
|
||||
throw err::Invalid{_Fmt{"Unable to handle destructor for element type %s"}
|
||||
% util::typeStr<TY>()};
|
||||
|
||||
// mark when target type is not trivially movable
|
||||
handling_.template probeMoveCapability<TY>();
|
||||
|
||||
// ensure sufficient element capacity or the ability to adapt element spread
|
||||
if (Coll::spread() < sizeof(TY) and not (Coll::empty() or handling_.canWildMove()))
|
||||
throw err::Invalid{_Fmt{"Unable to place element of type %s (size=%d)"
|
||||
"into container for element size %d."}
|
||||
% util::typeStr<TY>() % sizeof(TY) % Coll::spread()};
|
||||
|
||||
size_t elmSiz = sizeof(TY);
|
||||
size_t newPos = Coll::size();
|
||||
size_t newCnt = Coll::empty()? INITIAL_ELM_CNT : newPos+1;
|
||||
adjustStorage (newCnt, max (elmSiz, Coll::spread()));
|
||||
Coll::data_->cnt = newPos+1;
|
||||
POL::template createAt<TY> (Coll::data_, newPos, forward<ARGS> (args)...);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
adjustStorage (size_t cnt, size_t spread)
|
||||
{
|
||||
size_t demand{cnt*spread};
|
||||
Coll::data_ = POL::realloc (Coll::data_, cnt,spread); /////////////////OOO anpassen
|
||||
size_t buffSiz{Coll::data_? Coll::data_->buffSiz : 0};
|
||||
if (demand == buffSiz)
|
||||
return;
|
||||
if (demand > buffSiz)
|
||||
{// grow into exponentially expanded new allocation
|
||||
size_t safetyLim = LUMIERA_MAX_ORDINAL_NUMBER * Coll::spread();
|
||||
size_t expandAlloc = min (safetyLim
|
||||
,max (2*buffSiz, demand));
|
||||
if (expandAlloc < demand)
|
||||
throw err::State{_Fmt{"Storage expansion for Several-collection "
|
||||
"exceeds safety limit of %d bytes"} % safetyLim
|
||||
,LERR_(SAFETY_LIMIT)};
|
||||
// allocate new storage block...
|
||||
size_t newCnt = expandAlloc / spread;
|
||||
if (newCnt * spread < expandAlloc) ++newCnt;
|
||||
Coll::data_ = POL::realloc (Coll::data_, newCnt,spread);
|
||||
}
|
||||
ENSURE (Coll::data_);
|
||||
if (spread != Coll::spread())
|
||||
if (handling_.canWildMove() and spread != Coll::spread())
|
||||
adjustSpread (spread);
|
||||
}
|
||||
|
||||
void
|
||||
fitStorage()
|
||||
{
|
||||
if (not Coll::data_) return;
|
||||
size_t demand{Coll::size() * Coll::spread()};
|
||||
Coll::data_ = POL::realloc (Coll::data_, demand);
|
||||
if (handling_.lock_move or not Coll::data_)
|
||||
return;
|
||||
Coll::data_ = POL::realloc (Coll::data_, Coll::size(), Coll::spread());
|
||||
}
|
||||
|
||||
/** move existing data to accommodate spread */
|
||||
|
|
@ -407,38 +463,6 @@ namespace lib {
|
|||
newPos += idx * newSpread;
|
||||
std::memmove (newPos, oldPos, util::min (oldSpread,newSpread));
|
||||
}
|
||||
|
||||
template<class IT>
|
||||
void
|
||||
emplaceCopy (IT& dataSrc)
|
||||
{
|
||||
using Val = std::remove_cv_t<typename IT::value_type>;
|
||||
emplaceElm<Val> (*dataSrc);
|
||||
}
|
||||
|
||||
template<class TY, typename...ARGS>
|
||||
void
|
||||
emplaceElm (ARGS&& ...args)
|
||||
{
|
||||
if (not handling_.template canDestroy<TY>())
|
||||
throw err::Invalid{_Fmt{"Unable to handle destructor for element type %s"}
|
||||
% util::typeStr<TY>()};
|
||||
|
||||
// mark when target type is not trivially movable
|
||||
handling_.template probeMoveCapability<TY>();
|
||||
|
||||
// ensure sufficient element capacity or the ability to adapt element spread
|
||||
if (Coll::spread() < sizeof(TY) and not (Coll::empty() or handling_.canWildMove()))
|
||||
throw err::Invalid{_Fmt{"Unable to place element of type %s (size=%d)"
|
||||
"into container for element size %d."}
|
||||
% util::typeStr<TY>() % sizeof(TY) % Coll::spread()};
|
||||
|
||||
size_t elmSiz = sizeof(TY);
|
||||
size_t newCnt = Coll::size()+1;
|
||||
adjustStorage (newCnt, max (elmSiz, Coll::spread()));
|
||||
Coll::data_->cnt = newCnt;
|
||||
POL::template createAt<TY> (Coll::data_, newCnt-1, forward<ARGS> (args)...);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -82403,8 +82403,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1717776954529" ID="ID_103031227" MODIFIED="1717779551508" TEXT="Basis-Implementierung">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1717776954529" ID="ID_103031227" MODIFIED="1717894195586" TEXT="Basis-Implementierung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#435e98" CREATED="1717801589821" ID="ID_1293735403" MODIFIED="1717803186231" TEXT="arbeitet explizit mit ArrayBucket">
|
||||
<icon BUILTIN="yes"/>
|
||||
<node COLOR="#338800" CREATED="1717801612658" ID="ID_1718482523" MODIFIED="1717803181303" TEXT="bezieht von dort detailierte Metadaten">
|
||||
|
|
@ -82414,52 +82414,104 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1717776962179" ID="ID_1142886481" MODIFIED="1717776966238" TEXT="wachsen">
|
||||
<node COLOR="#338800" CREATED="1717779506814" ID="ID_584325941" MODIFIED="1717894192704" TEXT="Objekte umkopieren">
|
||||
<linktarget COLOR="#ec1c03" DESTINATION="ID_584325941" ENDARROW="Default" ENDINCLINATION="167;18;" ID="Arrow_ID_1090340504" SOURCE="ID_184907732" STARTARROW="None" STARTINCLINATION="178;0;"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#435e98" CREATED="1717776994933" ID="ID_916393989" MODIFIED="1717894075291" TEXT="Problem: nicht genau passende Storage">
|
||||
<arrowlink COLOR="#6045d8" DESTINATION="ID_1878698297" ENDARROW="Default" ENDINCLINATION="13;-122;" ID="Arrow_ID_605494253" STARTARROW="None" STARTINCLINATION="-437;29;"/>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1717777049607" ID="ID_184907732" MODIFIED="1717894184170" TEXT="brauche den konkreten Zieltyp hier">
|
||||
<arrowlink COLOR="#ec1c03" DESTINATION="ID_584325941" ENDARROW="Default" ENDINCLINATION="167;18;" ID="Arrow_ID_1090340504" STARTARROW="None" STARTINCLINATION="178;0;"/>
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1717858632242" HGAP="37" ID="ID_230351736" MODIFIED="1717894176693" TEXT="korrekte Methode für Verschiebung wählen" VSHIFT="28">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1717894097677" ID="ID_296210161" MODIFIED="1717894105895" TEXT="entweder memmove"/>
|
||||
<node CREATED="1717894106512" ID="ID_1351589328" MODIFIED="1717894141182">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
oder es wird <b>ausschließlich</b> der Element-Typ E konstruiert
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1717894127145" ID="ID_774641997" MODIFIED="1717894180642" TEXT="andere Fälle werden nicht zugelassen">
|
||||
<icon BUILTIN="flag-pink"/>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1717894315160" ID="ID_1788527715" MODIFIED="1717894325877" TEXT="auf welcher Ebene wird das geprüft?">
|
||||
<icon BUILTIN="help"/>
|
||||
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1717894328830" ID="ID_1955150114" MODIFIED="1717894371012">
|
||||
<richcontent TYPE="NODE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Vorsicht: hab es aus der <font face="Monospaced" color="#6a2f3c"><b>emplaceElm()</b></font>-Funktion entfernt
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
<node CREATED="1717894410331" ID="ID_732905043" MODIFIED="1717894437670" TEXT="es genügt, die move_lock-Flag zu prüfen">
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1717894472499" ID="ID_534883946" MODIFIED="1717894525092" TEXT="Aber: wird erst relevant wenn tatsächlich Objekte verschoben werden müssen">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...und das kann vom Allokator abhängen
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
<icon BUILTIN="flag-pink"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1717893861445" ID="ID_405289980" MODIFIED="1717893885331" TEXT="Kapazitäts-Steuerung ">
|
||||
<node COLOR="#338800" CREATED="1717776973613" ID="ID_1749910669" MODIFIED="1717776980785" TEXT="exponentielle Erweiterung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1717776981387" ID="ID_631542593" MODIFIED="1717776987939" TEXT="safety-Limit einbauen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1717779506814" ID="ID_584325941" MODIFIED="1717779525853" TEXT="Objekte umkopieren">
|
||||
<linktarget COLOR="#ec1c03" DESTINATION="ID_584325941" ENDARROW="Default" ENDINCLINATION="167;18;" ID="Arrow_ID_1090340504" SOURCE="ID_184907732" STARTARROW="None" STARTINCLINATION="178;0;"/>
|
||||
<icon BUILTIN="pencil"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1717776994933" ID="ID_916393989" MODIFIED="1717777035492" TEXT="Problem: nicht genau passende Storage">
|
||||
<arrowlink COLOR="#d84591" DESTINATION="ID_1878698297" ENDARROW="Default" ENDINCLINATION="13;-122;" ID="Arrow_ID_605494253" STARTARROW="None" STARTINCLINATION="-436;31;"/>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1717776966802" ID="ID_1301179349" MODIFIED="1717776969877" TEXT="schrumpfen">
|
||||
<node COLOR="#338800" CREATED="1717779536089" ID="ID_1997959648" MODIFIED="1717779542019" TEXT="leer-Fall ausschließen">
|
||||
<node COLOR="#338800" CREATED="1717893927188" ID="ID_407717086" MODIFIED="1717893962751" TEXT="leeren Container gleich mit einer größeren Allokation starten">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1717779506814" ID="ID_1523639170" MODIFIED="1717779525853" TEXT="Objekte umkopieren">
|
||||
<linktarget COLOR="#ec1c03" DESTINATION="ID_1523639170" ENDARROW="Default" ENDINCLINATION="167;18;" ID="Arrow_ID_15683997" SOURCE="ID_184907732" STARTARROW="None" STARTINCLINATION="178;0;"/>
|
||||
<icon BUILTIN="pencil"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1717777049607" ID="ID_184907732" MODIFIED="1717779530415" TEXT="brauche den konkreten Zieltyp hier">
|
||||
<arrowlink COLOR="#ec1c03" DESTINATION="ID_584325941" ENDARROW="Default" ENDINCLINATION="167;18;" ID="Arrow_ID_1090340504" STARTARROW="None" STARTINCLINATION="178;0;"/>
|
||||
<arrowlink COLOR="#ec1c03" DESTINATION="ID_1523639170" ENDARROW="Default" ENDINCLINATION="167;18;" ID="Arrow_ID_15683997" STARTARROW="None" STARTINCLINATION="178;0;"/>
|
||||
<icon BUILTIN="flag-pink"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1717858632242" HGAP="33" ID="ID_230351736" MODIFIED="1717858646313" TEXT="korrekte Methode für Verschiebung wählen" VSHIFT="23">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1717893967870" ID="ID_1707818601" MODIFIED="1717894043447" TEXT="Spread-Anpassung zweistufig">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1717893983028" ID="ID_571700268" MODIFIED="1717893999382" TEXT="wenn realloc ⟹ passiert implizit"/>
|
||||
<node CREATED="1717893999973" ID="ID_78281418" MODIFIED="1717894037217" TEXT="sonst ∧ wildMove ⟹ Positionen schieben"/>
|
||||
</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 BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1717894220868" HGAP="30" ID="ID_1883351365" MODIFIED="1717894241964" TEXT="muß passieren sobald wir ein ArrayBucket erstellen" VSHIFT="24">
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
</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 COLOR="#338800" CREATED="1717723703235" ID="ID_239148471" MODIFIED="1717894210685" TEXT="Objekt platzieren mit durchgereichten ctor-Argumenten">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1717770993835" ID="ID_1878698297" MODIFIED="1717777028572" TEXT="Problem: Größe der Basis-Allokation">
|
||||
<linktarget COLOR="#d84591" DESTINATION="ID_1878698297" ENDARROW="Default" ENDINCLINATION="13;-122;" ID="Arrow_ID_605494253" SOURCE="ID_916393989" STARTARROW="None" STARTINCLINATION="-436;31;"/>
|
||||
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1717770993835" ID="ID_1878698297" MODIFIED="1717894070187" TEXT="Problem: Größe der Basis-Allokation">
|
||||
<linktarget COLOR="#6045d8" DESTINATION="ID_1878698297" ENDARROW="Default" ENDINCLINATION="13;-122;" ID="Arrow_ID_605494253" SOURCE="ID_916393989" STARTARROW="None" STARTINCLINATION="-437;29;"/>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
<node CREATED="1717771028662" ID="ID_1266328566" MODIFIED="1717771040728" TEXT="diese könnte....">
|
||||
<node CREATED="1717771041580" ID="ID_710954788" MODIFIED="1717771046512" TEXT="überdimensioniert sein"/>
|
||||
|
|
@ -82655,6 +82707,12 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#c8c0b6" CREATED="1717893564694" ID="ID_1103861799" MODIFIED="1717893761226" TEXT="Anordnung">
|
||||
<icon BUILTIN="yes"/>
|
||||
<node CREATED="1717893609695" ID="ID_1949866055" MODIFIED="1717893656113" TEXT="die ElementFactory soll die Speicher-Handling-Primitive bereitstellen"/>
|
||||
<node CREATED="1717893571108" ID="ID_1720093628" MODIFIED="1717893608802" TEXT="die AllocationPolicy soll abstrahierte Basis-Operationen bereitstellen"/>
|
||||
<node CREATED="1717893657320" ID="ID_1877336986" MODIFIED="1717893750263" TEXT="die eigentliche Logik zur Kapazitätssteuerung ⟶ SeveralBuilder::adjustStorage()"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1717857964116" ID="ID_1398927698" MODIFIED="1717858080950" TEXT="spread-Erweiterung korrekt handhaben">
|
||||
<linktarget COLOR="#494890" DESTINATION="ID_1398927698" ENDARROW="Default" ENDINCLINATION="-414;28;" ID="Arrow_ID_834912184" SOURCE="ID_1036114720" STARTARROW="None" STARTINCLINATION="389;36;"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue