40using std::numeric_limits;
64 static_assert (0 < i);
94 return { place_object<1>
160 char c1(123), c2(45);
166 CHECK (1 ==ref1.getID());
167 CHECK (123==ref2.getID());
168 CHECK (45 ==ref3.getID());
188 vector<AllocationCluster> clusters (NUM_CLUSTERS);
189 for (
auto& clu : clusters)
198 for (
uint i=0; i<NUM_OBJECTS; ++i)
202 CHECK (checksum == NUM_OBJECTS * 223);
205 CHECK (allSum == checksum);
232 auto& i1 = clu.
create<uint16_t> (1 + uint16_t(
rani()));
238 CHECK (clu.
storage_.
rest == EXTSIZ - (2*
sizeof(
void*) +
sizeof(uint16_t)));
241 byte* blk =
static_cast<std::byte*
>(clu.
storage_.
pos);
246 auto currBlock = [&]{
247 byte* blk =
static_cast<std::byte*
>(clu.
storage_.
pos);
251 auto posOffset = [&]{
252 return size_t(clu.
storage_.
pos) - size_t(currBlock());
254 auto slot = [&](
size_t i)
256 size_t* slot =
reinterpret_cast<size_t*
> (currBlock());
260 CHECK (blk == currBlock());
262 CHECK (posOffset() == 2 *
sizeof(
void*) +
sizeof(uint16_t));
263 CHECK (slot(0) == 0);
267 auto& i2 = clu.
create<uint16_t> (55555);
268 CHECK (posOffset() == 2 *
sizeof(
void*) + 2 *
sizeof(uint16_t));
273 CHECK (slot(0) == 0);
274 CHECK (slot(1) == 0);
277 char& c1 = clu.
create<
char> (
'X');
278 CHECK (posOffset() == 2 *
sizeof(
void*) + 2 *
sizeof(uint16_t) +
sizeof(
char));
279 auto& i3 = clu.
create<int32_t> (42);
280 CHECK (posOffset() == 2 *
sizeof(
void*) + 2 *
sizeof(uint16_t) +
sizeof(
char) + 3*
sizeof(
byte) +
sizeof(int32_t));
285 CHECK (slot(0) == 0);
291 CHECK (posOffset() == EXTSIZ);
292 CHECK (clu.
numBytes() == EXTSIZ - 2*
sizeof(
void*));
294 CHECK (slot(0) == 0);
295 CHECK (blk == currBlock());
298 char& c2 = clu.
create<
char> (
'U');
299 CHECK (blk != currBlock());
300 CHECK (getAdr(c2) == currBlock() + 2*
sizeof(
void*));
302 CHECK (clu.
numBytes() == EXTSIZ - 2*
sizeof(
void*) + 1);
304 CHECK (slot(0) ==
size_t(blk));
312 size_t pp = posOffset();
314 CHECK (o1.getID() == 4);
316 CHECK (checksum == 4+4);
317 CHECK (
alignof(
Dummy<2>) ==
alignof(
char));
318 CHECK (posOffset() - pp ==
sizeof(
Dummy<2>));
324 CHECK (o2.getID() == 8);
325 CHECK (checksum == markSum + 8+8);
326 CHECK (posOffset() - pp >
sizeof(
Dummy<2>) + 2*
sizeof(
void*));
328 CHECK (
size_t(&o2) - slot(1) == 2*
sizeof(
void*));
330 auto dtor = (Dtor*)slot(1);
331 CHECK (dtor->next ==
nullptr);
336 string& s1 = clu.
create<
string> (rands);
339 CHECK (posOffset() - pp >=
sizeof(
string) + 2*
sizeof(
void*));
340 CHECK (
size_t(&s1) - slot(1) == 2*
sizeof(
void*));
341 auto dtor2 = (Dtor*)slot(1);
342 CHECK (dtor2->next == dtor);
343 CHECK (dtor->next ==
nullptr);
350 CHECK (checksum == markSum + 8+8 +
uchar(223*3));
351 auto dtor3 = (Dtor*)slot(1);
352 CHECK (dtor3->next ==
nullptr);
353 CHECK (dtor3 != dtor2);
354 CHECK (dtor2->next == dtor);
355 CHECK (dtor->next ==
nullptr);
363 CHECK (o1.getID() == 4);
364 CHECK (o2.getID() == 8);
365 CHECK (o3.getID() == 3);
367 CHECK (checksum == markSum);
386 using VecI = std::vector<uint16_t, Allo<uint16_t>>;
387 using Strg = std::basic_string<char, std::char_traits<char>,
Allo<char>>;
388 using SetS = std::set<Strg, std::less<Strg>,
Allo<Strg>>;
404 CHECK (vecI.capacity() == 64);
409 for (
uint i=0; i<NUM_OBJECTS; ++i)
410 setS.emplace (test::randStr(32), clu.
getAllocator<
char>());
411 CHECK (setS.size() > 0.9 * NUM_OBJECTS);
415 CHECK (
explore(vecI).resultSum() == sum(64));
425 auto& l1 = clu.
create<array<uchar,12>>();
429 auto& l2 = clu.
create<array<uchar,5>>();
440 CHECK (not clu.
canAdjust (&l2, 5, 1000));
454 using LERR_(INVALID);
465 CHECK (l1[11] == 11);
479 CHECK (l1[11] == 11);
Memory management for the low-level model (render nodes network).
A pile of objects sharing common allocation and lifecycle.
static constexpr size_t EXTENT_SIZ
hard wired size of storage extents
void doAdjust(void *loc, size_t oldSiz, size_t newSiz)
Adjust the size of the latest raw memory allocation dynamically.
bool canAdjust(void *loc, size_t oldSiz, size_t newSiz) const
size_t numExtents() const
TY & createDisposable(ARGS &&...)
Allocator< X > getAllocator()
A Dummy object for tests.
array< uchar, i > content_
Helpers typically used while writing tests.
Building tree expanding and backtracking evaluations within hierarchical scopes.
array< function< void(AllocationCluster &, uchar)>, NUM_TYPES > buildTrampoline()
void place_object(AllocationCluster &clu, uchar id)
void fill(AllocationCluster &clu)
string showSizeof(size_t siz, string name)
for printing sizeof().
string randStr(size_t len)
create garbage string of given length
Implementation namespace for support and library code.
auto explore(IT &&srcSeq)
start building a IterExplorer by suitably wrapping the given iterable source.
int rani(uint bound=_iBOUND())
Test runner and basic definitions for tests.
const void * getAdr(X &x)
extract address but strip any type info
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
#define MAX(A, B)
the inevitable MAX macro, sometimes still necessary in template code