10 releases

0.4.0 Aug 3, 2023
0.3.4 May 26, 2023
0.3.3 Jan 28, 2021
0.2.1 Jan 27, 2021
0.1.1 Jan 27, 2021

#312 in Memory management

Download history 809/week @ 2024-08-07 859/week @ 2024-08-14 1133/week @ 2024-08-21 1116/week @ 2024-08-28 1755/week @ 2024-09-04 1037/week @ 2024-09-11 1448/week @ 2024-09-18 1115/week @ 2024-09-25 954/week @ 2024-10-02 1524/week @ 2024-10-09 2045/week @ 2024-10-16 1599/week @ 2024-10-23 1983/week @ 2024-10-30 2792/week @ 2024-11-06 2960/week @ 2024-11-13 2778/week @ 2024-11-20

10,755 downloads per month
Used in 5 crates (3 directly)

MIT license

7KB
107 lines

alloca-rs

Build Status Latest Version Documentation

Mostly safe no_std wrapper for alloca in Rust.

This crate uses Rust lifetime system to ensure that stack allocated memory will not be used after function return, but it does not make any guarantee about memory that is turned into raw pointer and stored somewhere else.

Example

fn main() {
    // allocate 128 bytes on the stack
    alloca::with_alloca(128, |memory| {
        // memory: &mut [MaybeUninit<u8>]
        assert_eq!(memory.len(), 128);
    });
}

lib.rs:

Mostly safe no_std wrapper for alloca in Rust.

This crate uses Rust lifetime system to ensure that stack allocated memory will not be used after function return, but it does not make any guarantee about memory that is turned into raw pointer and stored somewhere else.

Example

// allocate 128 bytes on the stack
alloca::with_alloca(128, |memory| {
    // memory: &mut [MaybeUninit<u8>]
    assert_eq!(memory.len(), 128);
});

No runtime deps

~0–280KB