// An empty arena has no items to iterate over.
{ int iterations = 0;
arena.ForEach([&](void* item) { iterations++; });
ASSERT_EQ(iterations, 0);
}
auto a1 = arena.Alloc<A>(42); auto b1 = arena.Alloc<B>("Obladi oblada"); auto a2 = arena.Alloc<A>(1337); auto b2 = arena.Alloc<B>("Yellow submarine"); auto b3 = arena.Alloc<B>("She's got a ticket to ride");
// Alloc returns a non-negative offset if the allocation succeeded.
ASSERT_TRUE(a1 >= 0);
ASSERT_TRUE(a2 >= 0);
ASSERT_TRUE(b1 >= 0);
ASSERT_TRUE(b2 >= 0);
ASSERT_TRUE(b3 >= 0);
// Typically, running the destructors of the elements in the arena will is // done manually like this:
arena.ForEach([](void* item) { ((Base*)item)->~Base(); });
arena.Clear();
ASSERT_EQ(sDtorItemA, 2);
ASSERT_EQ(sDtorItemB, 3);
// An empty arena has no items to iterate over (we just cleared it).
{ int iterations = 0;
arena.ForEach([&](void* item) { iterations++; });
ASSERT_EQ(iterations, 0);
}
}
// A non-growable arena should return a negative offset when running out // of space, without crashing. // We should not run out of space with a growable arena (unless the os is // running out of memory but this isn't expected for this test). bool reachedLimit = false; for (int i = 0; i < 100; ++i) { auto offset = arena.Alloc<A>(42); if (offset < 0) {
reachedLimit = true; break;
}
}
ASSERT_EQ(reachedLimit, aShouldReachLimit);
}
IterableArena arena(IterableArena::GROWABLE, 16); // sizeof(BigStruct) is more than twice the initial capacity, make sure that // this doesn't blow everything up, since the arena doubles its storage size // each time it grows (until it finds a size that fits). auto a = arena.Alloc<BigStruct>(1); auto b = arena.Alloc<BigStruct>(2); auto c = arena.Alloc<BigStruct>(3);
// Offsets should also still point to the appropriate values after // reallocation.
ASSERT_EQ(((BigStruct*)arena.GetStorage(a))->mVal, (uint64_t)1);
ASSERT_EQ(((BigStruct*)arena.GetStorage(b))->mVal, (uint64_t)2);
ASSERT_EQ(((BigStruct*)arena.GetStorage(c))->mVal, (uint64_t)3);
arena.Clear();
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.