3 releases

0.2.2 Oct 21, 2022
0.2.1 Jan 19, 2020
0.2.0 Jan 17, 2020

#483 in Memory management

Download history 1635/week @ 2024-03-14 1545/week @ 2024-03-21 1829/week @ 2024-03-28 1800/week @ 2024-04-04 1743/week @ 2024-04-11 1883/week @ 2024-04-18 2102/week @ 2024-04-25 2305/week @ 2024-05-02 2676/week @ 2024-05-09 5617/week @ 2024-05-16 7060/week @ 2024-05-23 8935/week @ 2024-05-30 6837/week @ 2024-06-06 6672/week @ 2024-06-13 5328/week @ 2024-06-20 4376/week @ 2024-06-27

25,416 downloads per month
Used in 33 crates (4 directly)

MIT license

155KB
2K 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