Added missing *_with_alignment allocation variants.
This commit is contained in:
parent
b135e8beb8
commit
55c64a3392
|
@ -110,6 +110,16 @@ impl MemArena {
|
||||||
memory
|
memory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allocates memory for and initializes a type T, returning a mutable reference to it.
|
||||||
|
///
|
||||||
|
/// Additionally, the allocation will be made with the given byte alignment or
|
||||||
|
/// the type's inherent alignment, whichever is greater.
|
||||||
|
pub fn alloc_with_alignment<'a, T: Copy>(&'a self, value: T, align: usize) -> &'a mut T {
|
||||||
|
let mut memory = unsafe { self.alloc_uninitialized_with_alignment(align) };
|
||||||
|
*memory = value;
|
||||||
|
memory
|
||||||
|
}
|
||||||
|
|
||||||
/// Allocates memory for a type `T`, returning a mutable reference to it.
|
/// Allocates memory for a type `T`, returning a mutable reference to it.
|
||||||
///
|
///
|
||||||
/// CAUTION: the memory returned is uninitialized. Make sure to initalize before using!
|
/// CAUTION: the memory returned is uninitialized. Make sure to initalize before using!
|
||||||
|
@ -149,6 +159,25 @@ impl MemArena {
|
||||||
memory
|
memory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allocates memory for `len` values of type `T`, returning a mutable slice to it.
|
||||||
|
/// All elements are initialized to the given `value`.
|
||||||
|
///
|
||||||
|
/// Additionally, the allocation will be made with the given byte alignment or
|
||||||
|
/// the type's inherent alignment, whichever is greater.
|
||||||
|
pub fn alloc_array_with_alignment<'a, T: Copy>(&'a self,
|
||||||
|
len: usize,
|
||||||
|
value: T,
|
||||||
|
align: usize)
|
||||||
|
-> &'a mut [T] {
|
||||||
|
let memory = unsafe { self.alloc_array_uninitialized_with_alignment(len, align) };
|
||||||
|
|
||||||
|
for v in memory.iter_mut() {
|
||||||
|
*v = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
memory
|
||||||
|
}
|
||||||
|
|
||||||
/// Allocates and initializes memory to duplicate the given slice, returning a mutable slice
|
/// Allocates and initializes memory to duplicate the given slice, returning a mutable slice
|
||||||
/// to the new copy.
|
/// to the new copy.
|
||||||
pub fn copy_slice<'a, T: Copy>(&'a self, other: &[T]) -> &'a mut [T] {
|
pub fn copy_slice<'a, T: Copy>(&'a self, other: &[T]) -> &'a mut [T] {
|
||||||
|
@ -161,6 +190,24 @@ impl MemArena {
|
||||||
memory
|
memory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allocates and initializes memory to duplicate the given slice, returning a mutable slice
|
||||||
|
/// to the new copy.
|
||||||
|
///
|
||||||
|
/// Additionally, the allocation will be made with the given byte alignment or
|
||||||
|
/// the type's inherent alignment, whichever is greater.
|
||||||
|
pub fn copy_slice_with_alignment<'a, T: Copy>(&'a self,
|
||||||
|
other: &[T],
|
||||||
|
align: usize)
|
||||||
|
-> &'a mut [T] {
|
||||||
|
let memory = unsafe { self.alloc_array_uninitialized_with_alignment(other.len(), align) };
|
||||||
|
|
||||||
|
for (v, other) in memory.iter_mut().zip(other.iter()) {
|
||||||
|
*v = *other;
|
||||||
|
}
|
||||||
|
|
||||||
|
memory
|
||||||
|
}
|
||||||
|
|
||||||
/// Allocates memory for `len` values of type `T`, returning a mutable slice to it.
|
/// Allocates memory for `len` values of type `T`, returning a mutable slice to it.
|
||||||
///
|
///
|
||||||
/// CAUTION: the memory returned is uninitialized. Make sure to initalize before using!
|
/// CAUTION: the memory returned is uninitialized. Make sure to initalize before using!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user