Expand description
Arena allocator for building bytes::Bytes without copying the final
payload.
Write into a Buffer, call freeze(), and get back
Bytes backed by arena memory. The slot or block returns to the arena
when the last Bytes reference drops.
§Arena selection
FixedArena is the recommended high-throughput path when one slot size
covers the workload. Fixed uses uniform slots and a bitmap claim path.
BuddyArena covers variable-size allocation from one shared region.
Requests are rounded up to powers of two, larger blocks split on demand,
and neighbors coalesce on release.
Both produce the same Buffer type with identical write and freeze
semantics.
§Quick start
use std::num::NonZeroUsize;
use arena_alligator::FixedArena;
use bytes::BufMut;
let arena = FixedArena::with_slot_capacity(
NonZeroUsize::new(1024).unwrap(),
NonZeroUsize::new(4096).unwrap(),
)
.build()
.unwrap();
let mut buf = arena.allocate().unwrap();
buf.put_slice(b"hello");
let bytes = buf.freeze();
assert_eq!(&bytes[..], b"hello");§Auto-spill
.auto_spill() changes overflow writes
from panic-on-capacity to heap spill. The arena allocation is released as
soon as the spill happens.
§Initialization policy
The default policy is InitPolicy::Uninit, which matches Rust’s common
writable-uninitialized-memory model: newly allocated capacity is not
zero-filled, and only the bytes written become visible in the
frozen Bytes.
InitPolicy::Zero clears reused arena memory before it is handed back to
a writer. That adds work on every allocation in exchange for a stronger
zero-on-allocate guarantee.
§Frozen slice retention
Freezing a buffer transfers ownership of the arena slot (or buddy block)
to the returned Bytes. Cloning or slicing that Bytes shares the
reference, so the arena memory stays pinned until every clone and slice is
dropped.
BytesExt::into_owned() copies frozen bytes into fresh owned mutable
storage.
§Async allocation
With the async-alloc feature, AsyncFixedArena and AsyncBuddyArena
provide allocate_async() which waits until capacity is available.
Structs§
- Async
Buddy Arena - Async-capable wrapper around
BuddyArena. - Async
Fixed Arena - Async-capable wrapper around
FixedArena. - Buddy
Arena - Buddy-backed arena allocator.
- Buddy
Arena Builder - Builder for
BuddyArena. - Buddy
Arena Metrics - Snapshot of buddy arena metrics.
- Buddy
Geometry - Validated buddy arena geometry.
- Buffer
- A writable buffer backed by arena memory.
- Buffer
Full Error - Buffer capacity exceeded.
- Fixed
Arena - Fixed-size slot arena allocator.
- Fixed
Arena Builder - Builder for
FixedArena. - Fixed
Arena Metrics - Snapshot of fixed arena metrics.
- Notify
Waiters - Per-order waiter system.
- Unfaulted
- An arena whose backing pages have not yet been faulted.
Enums§
- Alloc
Error - Allocation failed.
- Build
Error - Builder configuration error.
- Init
Policy - Initialization policy applied to each buffer on allocate.
- Page
Size - Page size used for prefaulting the arena backing allocation.
Traits§
- Buddy
Waiter - Wait strategy for buddy arena async allocation.
- Bytes
Ext - Extension methods for converting
Bytesinto owned mutable storage. - Wait
Registration - Registration returned by waiter traits.
- Waiter
- Wait strategy for fixed arena async allocation.