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

#298 in Memory management

Download history 178/week @ 2024-01-02 72/week @ 2024-01-09 54/week @ 2024-01-16 27/week @ 2024-01-23 68/week @ 2024-01-30 53/week @ 2024-02-06 43/week @ 2024-02-13 211/week @ 2024-02-20 315/week @ 2024-02-27 249/week @ 2024-03-05 216/week @ 2024-03-12 230/week @ 2024-03-19 307/week @ 2024-03-26 89/week @ 2024-04-02 74/week @ 2024-04-09 108/week @ 2024-04-16

647 downloads per month
Used in 3 crates

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

~175KB