[−][src]Struct aligned_box::AlignedBox
A wrapper around std::boxed::Box
which allows allocating aligned heap memory. An instance of
AlignedBox<T>
consists of a Box<T>
and the std::alloc::Layout
that has been used to
allocate the referenced memory.
Implementations
impl<T: ?Sized> AlignedBox<T>
[src]
pub fn into_raw_parts(from: AlignedBox<T>) -> (*mut T, Layout)
[src]
Decompose the AlignedBox
into a raw pointer and the layout used during allocation.
The caller of this function becomes responsible for proper deallocation of the memory
behind the pointer. This can for example be done by reconstructing the AlignedBox
using
AlignedBox::from_raw_parts
.
pub unsafe fn from_raw_parts(ptr: *mut T, layout: Layout) -> AlignedBox<T>
[src]
Construct an AlignedBox
from a raw pointer and the layout that has been used to allocate
the memory behind that pointer. After calling this function, the pointer is owned by the
AlignedBox
. In particular, the memory will be freed when the AlignedBox
is dropped.
This is only safe if the given layout is the same as the one that was used during memory
allocation.
Safety
The function is unsafe because improper use can lead to issues, such as double-free. Also, behavior is undefined if the given layout does not correspond to the one used for allocation.
impl<T> AlignedBox<T>
[src]
pub fn new(alignment: usize, value: T) -> Result<AlignedBox<T>, Box<dyn Error>>
[src]
Store value
of type T
on the heap, making sure that it is aligned to a multiple of
alignment
. It is also checked if alignment
is a valid alignment for type T
or
increased to a valid alignment otherwise.
Example
Place value 17 of type i32
on the heap, aligned to 64 bytes:
use aligned_box::AlignedBox; let b = AlignedBox::<i32>::new(64, 17);
impl<T: Default> AlignedBox<[T]>
[src]
pub fn slice_from_default(
alignment: usize,
nelems: usize
) -> Result<AlignedBox<[T]>, Box<dyn Error>>
[src]
alignment: usize,
nelems: usize
) -> Result<AlignedBox<[T]>, Box<dyn Error>>
Allocate memory for nelems
values of type T
on the heap, making sure that it is aligned
to a multiple of alignment
. All values are initialized by the default value of type T
.
It is also checked if alignment
is a valid alignment for type T
or increased to a
valid alignment otherwise.
Example
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);
impl<T: Copy> AlignedBox<[T]>
[src]
pub fn slice_from_value(
alignment: usize,
nelems: usize,
value: T
) -> Result<AlignedBox<[T]>, Box<dyn Error>>
[src]
alignment: usize,
nelems: usize,
value: T
) -> Result<AlignedBox<[T]>, Box<dyn Error>>
Allocate memory for nelems
values of type T
on the heap, making sure that it is aligned
to a multiple of alignment
. All values are initialized by copies of value
. It is also
checked if alignment
is a valid alignment for type T
or increased to a
valid alignment otherwise.
Example
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);
Trait Implementations
impl<T: Clone + ?Sized> Clone for AlignedBox<T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: ?Sized> Deref for AlignedBox<T>
[src]
impl<T: ?Sized> DerefMut for AlignedBox<T>
[src]
impl<T: ?Sized> Drop for AlignedBox<T>
[src]
Auto Trait Implementations
impl<T: ?Sized> RefUnwindSafe for AlignedBox<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T: ?Sized> Send for AlignedBox<T> where
T: Send,
T: Send,
impl<T: ?Sized> Sync for AlignedBox<T> where
T: Sync,
T: Sync,
impl<T: ?Sized> Unpin for AlignedBox<T>
impl<T: ?Sized> UnwindSafe for AlignedBox<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,