Ray's Knowledge Base
Unlock

A pool limit caps reservations only; PoolAllocator allocations are counted, not capped

DecisionVerified 5 Nov 2026Holds project: dftracer-utils
Decision. The context, the choice, why, and the options that were turned down.

Context#

memory::Pool became public in memory/pool.h because public PoolAllocator and dstd::StringIntern take one. A review found that the pool limit caps only reservations, and a 64 MB limit in the first docs example bound nothing.

Decision#

The public pool offers: create a child with a name and a limit, name, path, kind, limit, stats (live, peak, blocks, reserved), try_reserve and the RAII Reservation. A user reserves before big work. try_reserve returns an empty Reservation when the pool is full. Allocations through PoolAllocator are counted, not checked against the limit. The Manager stays in memory/detail/. Users get memory::configure, the root pool and its stats.

Why#

The engine already works this way: reserve first, then allocate. A check on every allocation adds cost to the hot path. A failed allocation inside a container means an exception or an abort, and the engine relies on "count, do not fail". A public manager would turn every change to the pool tree or the reclaim logic into an API change.

Rejected options#

  • PoolAllocator checks the limit on each allocation and fails when full: slower, changes engine behavior.
  • Keep Pool in detail/ behind an opaque handle: adds a wrapper layer, and users cannot make their own pools.
  • A public Manager: users could call engine steps in the wrong order.

Also found by searching

  • what does a public memory pool limit do
  • PoolAllocator does not fail when the pool limit is exceeded
  • should the memory manager be public
  • how do I stay within a pool budget