Skip to content
CryoCryo home
StdlibFoundations

alloc

Everything that touches the heap lives in alloc. It gives you three things: a description of a memory request (Layout), a trait that anything serving those requests implements (Allocator), and the owning pointers built on top — Box, Rc, Arc — plus two allocation strategies, Arena and Pool, that you can substitute for the default.

public module alloc::layout;
public module alloc::allocator;
public module alloc::box;
public module alloc::arena;
public module alloc::arena_alloc;
public module alloc::pool;
public module alloc::heap;
public module alloc::rc;
public module alloc::arc;

Types here own storage. Each one exposes drop(mut &this), and its documentation names who is responsible for calling it. In practice the compiler synthesises the call at scope exit; a manual .drop() remains available for early release.

FileWhat it holdsImport
layoutLayout, a size and an alignmentimport std::alloc::layout;
allocatorThe Allocator trait, AllocError, GlobalAllocimport std::alloc::allocator;
boxBox<T, A>, unique heap ownership(prelude)
rcRc<T, A> and its Weak, single-threaded sharing(prelude)
arcArc<T, A> and its Weak, cross-thread sharingimport std::alloc::arc;
arenaArena, bump allocation with bulk releaseimport std::alloc::arena;
poolPool, fixed-size slots on a free listimport std::alloc::pool;

Two files have no page of their own. alloc::arena_alloc holds Arena's Allocator and Drop impls — split out because allocator imports arena and the module graph rejects cycles; they are listed on the arena page. alloc::heap is the mmap-backed segment heap behind GlobalAlloc when the compiler is built with native_alloc; you never call it directly.