#alloc #rc #vec #box #list #global-allocator #build

no-std without-alloc

Replacements for Box, Rc, Vec, .. without alloc

2 releases

0.2.1 Jan 19, 2020
0.2.0 Jan 17, 2020

#130 in Memory management

Download history 3342/week @ 2022-03-12 3279/week @ 2022-03-19 1689/week @ 2022-03-26 3251/week @ 2022-04-02 2505/week @ 2022-04-09 3439/week @ 2022-04-16 3795/week @ 2022-04-23 3847/week @ 2022-04-30 2199/week @ 2022-05-07 2561/week @ 2022-05-14 2393/week @ 2022-05-21 2249/week @ 2022-05-28 1596/week @ 2022-06-04 1944/week @ 2022-06-11 1847/week @ 2022-06-18 1220/week @ 2022-06-25

7,020 downloads per month
Used in 28 crates (3 directly)

MIT license

100KB
1.5K SLoC

without-alloc

Crates.io Status Docs.rs Status License CI Status

Dynamic data structures that do not require a global allocator.

Usage

This allows creating dynamic and recursive data structures without dynamic allocations. The example below makes use of the static-alloc crate to build a list with static lifetime based on dynamic data. As local memory pools for fixed capacity FixedVec:

use static_alloc::Bump;
use without_alloc::{FixedVec, alloc::LocalAllocLeakExt};

let mut pool: Bump<[usize; 16]> = Bump::uninit();
// Allocate a vector with capacity of 16 from the slab.
let mut vector = pool.fixed_vec(16).unwrap();

let mut num = 0;
// Push mutable ref, not `'static`, `Copy` nor `Clone`!
vector.push(&mut num);
*vector[0] = 42;

drop(vector);
assert_eq!(num, 42);

This might be handy if you want to chain boot another kernel and pass it a linked list describing the platform.

use static_alloc::Bump;
use without_alloc::{Box, alloc::LocalAllocLeakExt};

enum List {
    Nil,
    Cons(u8, Box<'static, List>),
}

static SLAB: Bump<[u8; 1024]> = Bump::uninit();

let base = SLAB.boxed(List::Nil).unwrap();
let one = SLAB.boxed(List::Cons(0, base)).unwrap();
let two = SLAB.boxed(List::Cons(1, one)).unwrap();

Dependencies