Files

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 on Core).
  • 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 into tests/package/InstalledComponents.cmake.

3. Exact files and interfaces

  • Resource.hpp: AllocationError, UnlimitedTag/unlimited, ResourceStats, is_valid_alignment.
  • BudgetResource.hpp: atomic CAS std::pmr::memory_resource with reservation rollback on upstream std::bad_alloc, overflow detection, zero-limit positive rejection.
  • Arena.hpp: fixed, growing, and initial+growing modes (64 KiB slab, 1 MiB geometric cap, 16 MiB default max), address-aligned bump allocation (explicit 1-byte reservation for 0-byte calls), Checkpoint/rewind/reset with generation checks, TypedScope (reverse dtor order, exception-safe emplace, 4,096 default registrations), ArenaResource.
  • BlockPool.hpp: per-slab intrusive free lists (zero allocations on deallocate, safe trim_idle of completely idle slabs, default 4,096 blocks / 16 MiB cap) and SynchronizedBlockPool.

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() returns invalid_checkpoint; reset()/rewind() while a TypedScope is live returns live_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=OFF installs and runs MemoryOnly with 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