#heap-memory #memory-alignment #alignment #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

#414 in Memory management

Download history 650/week @ 2026-01-06 633/week @ 2026-01-13 545/week @ 2026-01-20 700/week @ 2026-01-27 709/week @ 2026-02-03 1007/week @ 2026-02-10 791/week @ 2026-02-17 1184/week @ 2026-02-24 556/week @ 2026-03-03 526/week @ 2026-03-10 606/week @ 2026-03-17 614/week @ 2026-03-24 586/week @ 2026-03-31 971/week @ 2026-04-07 881/week @ 2026-04-14 1142/week @ 2026-04-21

3,805 downloads per month
Used in 5 crates (2 directly)

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