Skip to main content

Crate arena_arc

Crate arena_arc 

Source
Expand description

A fast, chunk-based allocator for building contiguous slices and sharing them via handles.

This crate provides Allocator to allocate variable-length slices from a pre-allocated chunk and return zero-copy [Handle]s. The handles share the underlying buffer and are cheap to clone.

§Safety notes

  • Zombie objects: When a previously allocated slice is no longer used but the same chunk is still held by other handles, that slice’s memory is not reclaimed individually. It is only reclaimed when the entire chunk is freed.
  • Extra memory overhead: Chunks are allocated with a fixed capacity N, which can leave unused space. When a request exceeds the remaining space, a new chunk is allocated and the unused tail of the old chunk becomes additional overhead.
  • Deferred drops: Elements are dropped only when the last handle for a chunk is released, so resource reclamation does not happen per element immediately.
  • Cycles with handles: If the allocated T contains an ArcSlice/ArcSingle created by the same allocator (directly or indirectly), this can form a reference cycle and prevent the chunk from ever being freed.

§Example

use arena_arc::Allocator;

let mut allocator: Allocator<u32, u32, 16> = Allocator::new();
let handle = allocator.alloc(4, |i| (i * 2) as u32);
assert_eq!(handle.get(), &[0, 2, 4, 6]);

Structs§

Allocator
Chunk-based allocator for variable-length slices.
ArcSingle
ArcSlice
A read-only handle to a slice allocated from an Allocator.

Traits§

IndexType
Trait bound for index types used by [Handle] and Allocator.