Library: verify further simple allocations and alignment

This commit is contained in:
Fischlurch 2024-05-24 19:06:33 +02:00
parent 037a5f2dd0
commit 841234684b
2 changed files with 40 additions and 22 deletions

View file

@ -202,49 +202,65 @@ namespace test {
CHECK (0==checksum);
{
AllocationCluster clu;
// no allocation happened yet
CHECK (0 == clu.numExtents());
CHECK (0 == clu.numBytes());
SHOW_EXPR(clu.storage_.rest);
SHOW_EXPR(size_t(clu.storage_.pos));
CHECK (nullptr == clu.storage_.pos);
CHECK ( 0 == clu.storage_.rest);
// build a simple object
auto& i1 = clu.create<uint16_t> (1 + uint16_t(rand()));
CHECK (i1 > 0);
CHECK (1 == clu.numExtents());
SHOW_EXPR(clu.numBytes())
CHECK (2 == clu.numBytes());
SHOW_EXPR(clu.storage_.rest);
SHOW_EXPR(size_t(clu.storage_.pos));
CHECK (clu.storage_.pos != nullptr);
CHECK (clu.storage_.pos == (& i1) + 1 ); // points directly behind the allocated integer
CHECK (clu.storage_.rest == BLOCKSIZ - (2*sizeof(void*) + sizeof(uint16_t)));
// Demonstration: how to reconstruct the start of the current extent
byte* blk = static_cast<std::byte*>(clu.storage_.pos);
SHOW_EXPR(size_t(blk));
blk += clu.storage_.rest - BLOCKSIZ;
SHOW_EXPR(size_t(blk));
SHOW_EXPR((size_t*)blk);
CHECK(size_t(blk) < size_t(clu.storage_.pos));
// some abbreviations for navigating the raw storage blocks...
auto currBlock = [&]{
byte* blk = static_cast<std::byte*>(clu.storage_.pos);
blk += clu.storage_.rest - BLOCKSIZ;
return blk;
};
auto posOffset = [&]{
return size_t(clu.storage_.pos) - size_t(currBlock());
};
auto slot = [&](size_t i)
{
size_t* slot = reinterpret_cast<size_t*> (currBlock());
return slot[i];
};
auto posOffset = [&]{
return size_t(clu.storage_.pos) - size_t(currBlock());
};
SHOW_EXPR(size_t(currBlock()))
SHOW_EXPR(slot(0))
SHOW_EXPR(slot(1))
SHOW_EXPR(size_t(clu.storage_.pos) - size_t(currBlock()))
CHECK (blk == currBlock());
// current storage pos: 2 »slots« of admin overhead plus the first allocated element
CHECK (posOffset() == 2 * sizeof(void*) + sizeof(uint16_t));
CHECK (slot(0) == 0); // only one extent, thus next-* is NULL
// allocate another one
uint16_t i1pre = i1;
auto& i2 = clu.create<uint16_t> (55555);
CHECK (posOffset() == 2 * sizeof(void*) + 2 * sizeof(uint16_t));
CHECK (clu.storage_.rest == BLOCKSIZ - posOffset());
// existing storage unaffected
CHECK (i1 == i1pre);
CHECK (i2 == 55555);
CHECK (slot(0) == 0);
// alignment is handled properly
char& c1 = clu.create<char> ('X');
CHECK (posOffset() == 2 * sizeof(void*) + 2 * sizeof(uint16_t) + sizeof(char));
auto& i3 = clu.create<int32_t> (42);
CHECK (posOffset() == 2 * sizeof(void*) + 2 * sizeof(uint16_t) + sizeof(char) + 3*sizeof(byte) + sizeof(int32_t));
CHECK (i1 == i1pre);
CHECK (i2 == 55555);
CHECK (c1 == 'X');
CHECK (i3 == 42);
CHECK (slot(0) == 0);
}
CHECK (0==checksum);

View file

@ -81708,8 +81708,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
mu&#223; hier leider eine schecklicke low-level-Trickserei machen; das ist die Konsequenz der Entscheidung, mit dem absolut minimalen Storage-Overhead zu arbeiten, und au&#223;erdem mu&#223; ich auch noch das Non-Copyable <i>aushebeln...</i>
</p>
</body>
</html>
</richcontent>
</html></richcontent>
<icon BUILTIN="button_ok"/>
</node>
<node COLOR="#338800" CREATED="1715820289221" ID="ID_1541316374" MODIFIED="1716130701433" TEXT="&#xdc;berlauf: neuen Block belegen">
@ -81912,14 +81911,17 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node COLOR="#338800" CREATED="1716552160019" ID="ID_146077309" MODIFIED="1716566510566" TEXT="die Mechanik &#xfc;berhaupt erst mal zum Laufen bekommen">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1716552180480" ID="ID_1382140920" MODIFIED="1716566512774" TEXT="eine Allokation im bestehenden Extent">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1716552180480" ID="ID_1382140920" MODIFIED="1716570347935" TEXT="eine Allokation im bestehenden Extent">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1716566627518" ID="ID_874153150" MODIFIED="1716566633607" TEXT="sieht erst mal gut aus">
<icon BUILTIN="button_ok"/>
</node>
<node COLOR="#338800" CREATED="1716566635117" ID="ID_674171131" MODIFIED="1716566656562" TEXT="lokale abk&#xfc;rzungs-&#x3bb; im Test">
<icon BUILTIN="button_ok"/>
</node>
<node COLOR="#338800" CREATED="1716570349907" ID="ID_1594023993" MODIFIED="1716570356962" TEXT="Alignment wird ber&#xfc;cksichtigt">
<icon BUILTIN="button_ok"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716552190584" ID="ID_1042988047" MODIFIED="1716552206544" TEXT="einen &#xdc;berlauf provozieren">
<icon BUILTIN="flag-yellow"/>