2.5 KiB
2.5 KiB
NEW Memory Subsystem Core Allocators and Resources
Task IDs: S-MEMORY-02, S-MEMORY-03, S-MEMORY-04 Phase: P1 Status: APPROVED Contracts: C-01, C-04, C-05
1. Context and baseline
No src/Memory module or include/Void/Memory headers exist yet. Containers and future IO/Storage modules need bounded PMR budget tracking, bump arenas with checkpoints/typed destructor scopes, and fixed-size block pools.
2. Deliverables
src/Memory/module.cmake(INTERFACE, depending only onCore).include/Void/Memory/{Resource.hpp,BudgetResource.hpp,Arena.hpp,BlockPool.hpp}.tests/standalone/Memory/{BudgetResource.cpp,Arena.cpp,BlockPool.cpp}.tests/package/MemoryOnly/{CMakeLists.txt,main.cpp}wired intotests/package/InstalledComponents.cmake.
3. Exact files and interfaces
Resource.hpp:AllocationError,UnlimitedTag/unlimited,ResourceStats,is_valid_alignment.BudgetResource.hpp: atomic CASstd::pmr::memory_resourcewith reservation rollback on upstreamstd::bad_alloc, overflow detection, zero-limit positive rejection.Arena.hpp: fixed, growing, and initial+growing modes (64 KiBslab,1 MiBgeometric cap,16 MiBdefault max), address-aligned bump allocation (explicit 1-byte reservation for 0-byte calls),Checkpoint/rewind/resetwith generation checks,TypedScope(reverse dtor order, exception-safeemplace, 4,096 default registrations),ArenaResource.BlockPool.hpp: per-slab intrusive free lists (zero allocations ondeallocate, safetrim_idleof completely idle slabs, default 4,096 blocks / 16 MiB cap) andSynchronizedBlockPool.
4. Edge cases
- Over-aligned (
alignas(64)) allocation inside a misaligned/stack fixed buffer aligns the actual pointer address rather than only the offset. - Stale checkpoint after
reset()returnsinvalid_checkpoint;reset()/rewind()while aTypedScopeis live returnslive_allocations. BlockPool::trim_idle()never touches slabs with live blocks and maintains intact per-slab free lists.
5. Acceptance criteria
- Standalone
-DVOID_ENABLED_MODULES=Memory -DVOID_ENABLE_TESTING=OFFinstalls and runsMemoryOnlywith zero external packages. - All Memory tests pass under ASan/UBSan and
-Werror.
6. Verification commands
dev cpp-gcc -c cmake -S . -B /tmp/void-p1-memory -G Ninja -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Debug -DVOID_ENABLED_MODULES="Memory;Testing" -DVOID_WARNINGS_AS_ERRORS=ON
dev cpp-gcc -c cmake --build /tmp/void-p1-memory --parallel 4
dev cpp-gcc -c ctest --test-dir /tmp/void-p1-memory --output-on-failure --timeout 60