Issue #1493: Choosing the allocator: a build, a task or a call names where memory comes from, and an allocation that may fail returns a value

Open and answer this issue on GitHub.

targets, decision, future, safety · opened 2026-11-09 · updated 2026-11-22 · 0 comments

Where it comes from

The owner asked (2026-11-09) whether the allocator can be configured, for bare-metal users who must control how memory is managed and for kernel work. This blocks nothing today; it is a question for a later version (future).

Today’s state

So the places where memory comes from are already parameters inside the runtime, but a program cannot choose one.

What other languages do

Language How an allocator is chosen A failed allocation
Rust one #[global_allocator] per program; per-collection allocators (Vec<T, A>) unstable for years aborts; try_reserve on some collections
Rust for Linux KVec, KBox take allocation flags (GFP_KERNEL, GFP_ATOMIC) on every allocating call returns Err(AllocError)
Zig every allocating function takes an Allocator parameter (FixedBufferAllocator, arena, page) returns error.OutOfMemory
C++ std::pmr::memory_resource per container throws bad_alloc
Odin an implicit context.allocator, set for a scope returns an error value
Go, Swift none; the runtime’s ends the program

Options

  1. Do nothing. Keep the system allocator, ADR-119’s region for bare-metal, and the task budget. For: nothing new to learn or check. Against: no pool, slab or arena for a program that needs one; kernel and hard real-time work stay out of reach.
  2. One allocator per build (allocator = "…" in [build], naming a described crate or a package that implements an Allocator trait), like Rust’s #[global_allocator]. For: small, no change to any signature. Against: one choice for the whole program; does not let one part use an arena and another the heap.
  3. Per task, through the block (#490): a task’s group may name the allocator its block is carved from (async(alloc: pool) { … }), as it names limit: today. For: fits the model already being built; the budget and OverBudget already give a failure path; nothing in ordinary signatures changes. Against: the granularity is a task, not a value.
  4. Per value or call, as in Zig: an allocator parameter on containers and allocating functions. For: most control. Against: colours every signature that allocates; Rust has not stabilised it in years for that reason; contradicts the inferred placement of ADR-283 D10.
  5. Allocations that may fail as values, independent of 2-4: a try_ form (or a build setting that makes every allocating call return a Result) so that out of memory is handled where it happens. For: required for kernels and safety-critical code. Against: a second form of every allocating entry, or a mode that changes types.

Recommendation

Option 2 together with 3, and 5 as a build setting for targets that need it (the kernel target, #1494): one allocator per build for the common case, a different one for a task where it matters, and failure as a value where the target demands it. Option 4 is refused for the reasons of ADR-283 D10. Decide once #490 has the block placement (step 5) and OverBudget built, since 3 builds on them.

Found while #490. Related: ADR-119, ADR-283 D7, ADR-284, ADR-327, ADR-348, #1489, #1494.

Back to Open Issues