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

#256 in Memory management

Download history 1046/week @ 2024-06-14 1154/week @ 2024-06-21 881/week @ 2024-06-28 838/week @ 2024-07-05 764/week @ 2024-07-12 921/week @ 2024-07-19 1149/week @ 2024-07-26 706/week @ 2024-08-02 837/week @ 2024-08-09 1043/week @ 2024-08-16 966/week @ 2024-08-23 1240/week @ 2024-08-30 1734/week @ 2024-09-06 1083/week @ 2024-09-13 1258/week @ 2024-09-20 1060/week @ 2024-09-27

5,352 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

~225KB