#heap-memory #aligned #heap #alignment #memory #box

no-std aligned_box

Allocate heap memory with user-specified alignment

3 unstable releases

0.3.0 Jun 8, 2024
0.2.1 Feb 27, 2021
0.2.0 Sep 1, 2020
0.1.0 Aug 23, 2020

#143 in Memory management

Download history 36/week @ 2024-03-28 22/week @ 2024-04-04 22/week @ 2024-04-11 13/week @ 2024-04-18 21/week @ 2024-04-25 10/week @ 2024-05-02 1/week @ 2024-05-16 1/week @ 2024-05-23 4/week @ 2024-05-30 174/week @ 2024-06-06 14/week @ 2024-06-13

299 downloads per month
Used in fips-md

MIT license

32KB
468 lines

aligned_box: Allocate aligned heap memory in Rust.

CI license crates.io docs.rs

This crate provides a wrapper around the Box type, which allows allocating heap memory with user-specified alignment.

Examples

Place value 17 of type i32 on the heap, aligned to 64 bytes:

use aligned_box::AlignedBox;
let b = AlignedBox::<i32>::new(64, 17);

Allocate memory for 1024 values of type f32 on the heap, aligned to 128 bytes. Values are initialized by their default value:

use aligned_box::AlignedBox;
let b = AlignedBox::<[f32]>::slice_from_default(128, 1024);

Allocate memory for 1024 values of type f32 on the heap, aligned to 128 bytes. All values are initialized with PI:

use aligned_box::AlignedBox;
let b = AlignedBox::<[f32]>::slice_from_value(128, 1024, std::f32::consts::PI);

No runtime deps