The State of Allocators in 2026 - 6 Months Later
In the six months since the last article on the state of allocators in Rust, there has been a significant resurgence of activity in getting custom allocators stabilized, with Nia leading the effort and the rest of the libs team supporting her. The allocator shape has remained largely unchanged from the nightly builds, with only a limited API surface providing two methods for the Allocator trait.
The main focus during stabilization was on whether Allocator could become dyn compatible, leading to the decision to make it dyn compatible straight off the bat. This change is considered a major improvement in nightly builds, as dynamic dispatching of allocators is not a concern for performance and offers greater flexibility. Another key point is the prohibition of unwinding from allocators, as previous issues with unsoundness were found when allowing it.
Currently, only Vec and Box are supported for custom allocators, making this an MVP for the feature. Additionally, there are ongoing discussions about what happens when an allocator is dropped, particularly whether it deallocates memory or just the engine for memory allocation. The introduction of an unsafe marker trait, AllocatorClone, aims to provide the necessary guarantees for cloning allocators without risking unsound code.
Rewritten by urgent.news; may contain errors — check the original.
Source: cetra3.github.io