Crate byte_arena

Source
Expand description

A statically sized arena for byte buffers.

This crate provides an Arena for allocation of dynmically sized byte buffers ([u8]) without dependency on std or alloc.

§Usage

use byte_arena::Arena;

// Create a new arena with 8KiB backing storage.
let mut arena = Arena::new([0; 8192]);

// Allocate a 1KiB buffer.
let mut buf = arena.alloc(1024).unwrap();
buf.fill(42);
// The index allows access to the allocation after the
// buffer has been dropped.
let mut buf_index = buf.index();

// Allocate a 1KiB zeroed buffer.
let mut zeroed_buf = arena.alloc(1024).unwrap();
let mut zeroed_buf_index = zeroed_buf.index();

let buf = arena.get(buf_index).unwrap();

arena.dealloc(buf_index);
arena.dealloc(zeroed_buf_index);

Note that the use of Index values between different Arena instances is not specified and may cause panics, corrupt the internal representations but will not cause undefined behavior.

Structs§

AllocError
Arena
A statically-sized arena for allocation of byte buffers.
Buf
BufMut
Index