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

aligned_box

Allocate heap memory with user-specified alignment

2 releases

0.2.1 Feb 27, 2021
0.2.0 Sep 1, 2020
0.1.0 Aug 23, 2020

#635 in Memory management

Download history 14/week @ 2024-01-29 6/week @ 2024-02-05 31/week @ 2024-02-12 48/week @ 2024-02-19 48/week @ 2024-02-26 27/week @ 2024-03-04 56/week @ 2024-03-11 9/week @ 2024-03-18 49/week @ 2024-03-25 32/week @ 2024-04-01 22/week @ 2024-04-08 16/week @ 2024-04-15

120 downloads per month
Used in fips-md

MIT license

32KB
461 lines

aligned_box: Allocate aligned heap memory in Rust.

build license crates.io docs.rs

This crate provides a wrapper around std::boxed::Box 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