mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 03:52:16 +02:00
Restored the monotonic allocator
This commit is contained in:
@ -28,56 +28,4 @@ TEST_CASE("MemoryPool::clear()") {
|
||||
|
||||
REQUIRE(memoryPool.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("Purges variant cache") {
|
||||
VariantSlot* a = memoryPool.allocVariant();
|
||||
REQUIRE(a != 0);
|
||||
VariantSlot* b = memoryPool.allocVariant();
|
||||
REQUIRE(b != 0);
|
||||
|
||||
// place slot a in the pool of free slots
|
||||
memoryPool.freeVariant(a);
|
||||
memoryPool.clear();
|
||||
|
||||
REQUIRE(memoryPool.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("Purges string cache") {
|
||||
StringSlot* a = memoryPool.allocFrozenString(10);
|
||||
REQUIRE(a != 0);
|
||||
StringSlot* b = memoryPool.allocFrozenString(10);
|
||||
REQUIRE(b != 0);
|
||||
|
||||
// place slot a in the pool of free slots
|
||||
memoryPool.freeString(a);
|
||||
memoryPool.clear();
|
||||
|
||||
REQUIRE(memoryPool.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("Purges list of string") {
|
||||
StringSlot* a = memoryPool.allocFrozenString(6);
|
||||
REQUIRE(a != 0);
|
||||
strcpy(a->value, "hello");
|
||||
|
||||
StringSlot* b = memoryPool.allocFrozenString(6);
|
||||
REQUIRE(b != 0);
|
||||
strcpy(b->value, "world");
|
||||
|
||||
memoryPool.clear(); // ACT!
|
||||
|
||||
StringSlot* c = memoryPool.allocFrozenString(2);
|
||||
REQUIRE(c != 0);
|
||||
strcpy(c->value, "H");
|
||||
|
||||
StringSlot* d = memoryPool.allocFrozenString(2);
|
||||
REQUIRE(d != 0);
|
||||
strcpy(d->value, "W");
|
||||
|
||||
// if the memory pool keeps pointer to the old strings
|
||||
// it will try to compact the strings
|
||||
memoryPool.freeString(c);
|
||||
|
||||
REQUIRE(d->value == std::string("W"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user