diff --git a/src/vault/mem/local-mem-pool.hpp b/src/vault/mem/local-mem-pool.hpp index 444e8b619..0a518406a 100644 --- a/src/vault/mem/local-mem-pool.hpp +++ b/src/vault/mem/local-mem-pool.hpp @@ -407,13 +407,13 @@ namespace mem { ENSURE (this->empty()); } - private: void ingest() { inQueue_.consume_all ([this](Alloc alloc){ supplyImmediately (move(alloc)); }); } + private: template Block const* findMatch (PRED&& predicate) const diff --git a/tests/vault/mem/local-mem-pool-test.cpp b/tests/vault/mem/local-mem-pool-test.cpp index fa435f8ae..35b953c72 100644 --- a/tests/vault/mem/local-mem-pool-test.cpp +++ b/tests/vault/mem/local-mem-pool-test.cpp @@ -19,11 +19,16 @@ #include "test/run.hpp" #include "test/test-helper.hpp" #include "vault/mem/local-mem-pool.hpp" +#include "lib/iter-explorer.hpp" #include "lib/iter-stack.hpp" #include "lib/format-util.hpp" +#include "test/diagnostic-output.hpp"////////////TODO +#include using util::join; +using lib::explore; +using std::invocable; namespace vault { namespace mem { @@ -302,6 +307,7 @@ namespace test { /** @test heuristic trigger mechanism for pool clean-up + * - use a setup where the global pool is just a queue of buffer pointers * - create abbreviated notation to play through various scenarios * - watch how turnover and max-score are computed for each step * - document the trigger points for heuristic clean-up. @@ -309,7 +315,101 @@ namespace test { void verify_turnoverTrigger() { + LocalMemPool pool; + lib::IterQueue globalPool; + lib::IterStack usedBuff; + size_t SIZ = SIZ10; + //------------ pretty printing of "allocations" + auto buffID = [](Buff* buff){ return size_t(buff); }; + auto show = [&](auto coll){ return join (explore(coll).transform(buffID)); }; + + + //------------ define abstracted form of the basic actions on the pool... + + auto pullMem = [&]{ // retrieve one allocation from global pool + if (globalPool) + { + pool.supply (*globalPool, SIZ); + pool.ingest(); + ++globalPool; + } + }; + + auto pushMem = [&](Buff* mem, size_t) + { // return one allocation into global pool + globalPool.feed (mem); + }; + + auto useMem = [&]{ // claim one allocation from local pool + auto [mem,_] = pool.retrieve (SIZ); + usedBuff.push(mem); + }; + + auto freeMem = [&]{ // return one used allocation into local pool + if (usedBuff) + { + pool.reSupply (*usedBuff); + ++usedBuff; + } + }; + + auto repeat = [](uint n, invocable<> auto action) + { + for (uint i=0; i - + + + + + + + + + + + + + + + + + + + + + +