4 releases
0.2.0 | May 21, 2024 |
---|---|
0.1.2 | May 16, 2024 |
0.1.1 | May 10, 2024 |
0.1.0 | May 10, 2024 |
#343 in Memory management
19KB
389 lines
byte-arena
no_std, no_alloc arena for allocating byte buffers.
Usage
Add byte-arena
to your Cargo.toml
:
byte-arena = "0.1.0"
Refer to docs.rs for the usage of this crate.
License
Licensed under either
- MIT License or
- Apache License, Version 2.0 at your option.
lib.rs
:
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.