[−][src]Struct alloc_compose::Chunk
Allocate memory with a multiple size of the provided chunk size.
Examples
#![feature(allocator_api, slice_ptr_len)] use alloc_compose::Chunk; use std::alloc::{AllocRef, Layout, System}; let mut alloc = Chunk::<_, 64>(System); let ptr = alloc.alloc(Layout::new::<[u8; 16]>())?; assert_eq!(ptr.len() % 64, 0); assert!(ptr.len() >= 64);
When growing or shrinking the memory, Chunk
will try to alter
the memory in place before delegating to the underlying allocator.
#![feature(slice_ptr_get)] let new_ptr = unsafe { alloc.grow( ptr.as_non_null_ptr(), Layout::new::<[u8; 16]>(), Layout::new::<[u8; 24]>(), )? }; assert_eq!(ptr, new_ptr);
This can be enforced by using ReallocateInPlace::grow_in_place
.
use alloc_compose::ReallocateInPlace; let len = unsafe { alloc.grow_in_place( ptr.as_non_null_ptr(), Layout::new::<[u8; 24]>(), Layout::new::<[u8; 32]>(), )? }; assert_eq!(len % 64, 0); assert!(len >= 64);
Trait Implementations
impl<A: AllocRef, const SIZE: usize> AllocRef for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo,
[src]
Self: SizeIsPowerOfTwo,
pub fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
[src]
pub fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
[src]
pub unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)
[src]
pub fn by_ref(&self) -> &Self
[src]
impl<A: Clone, const SIZE: usize> Clone for Chunk<A, SIZE>
[src]
pub fn clone(&self) -> Chunk<A, SIZE>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A: Copy, const SIZE: usize> Copy for Chunk<A, SIZE>
[src]
impl<A: Debug, const SIZE: usize> Debug for Chunk<A, SIZE>
[src]
impl<A: Default, const SIZE: usize> Default for Chunk<A, SIZE>
[src]
impl<A: Eq, const SIZE: usize> Eq for Chunk<A, SIZE>
[src]
impl<A: Owns, const SIZE: usize> Owns for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo,
[src]
Self: SizeIsPowerOfTwo,
impl<A: PartialEq, const SIZE: usize> PartialEq<Chunk<A, SIZE>> for Chunk<A, SIZE>
[src]
pub fn eq(&self, other: &Chunk<A, SIZE>) -> bool
[src]
pub fn ne(&self, other: &Chunk<A, SIZE>) -> bool
[src]
impl<A, const SIZE: usize> ReallocateInPlace for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo,
[src]
Self: SizeIsPowerOfTwo,
pub unsafe default fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
pub unsafe default fn grow_in_place_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
pub unsafe default fn shrink_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
impl<A: ReallocateInPlace, const SIZE: usize> ReallocateInPlace for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo,
[src]
Self: SizeIsPowerOfTwo,
pub unsafe fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
pub unsafe fn grow_in_place_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
pub unsafe fn shrink_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
impl<A, const SIZE: usize> StructuralEq for Chunk<A, SIZE>
[src]
impl<A, const SIZE: usize> StructuralPartialEq for Chunk<A, SIZE>
[src]
Auto Trait Implementations
impl<A, const SIZE: usize> Send for Chunk<A, SIZE> where
A: Send,
A: Send,
impl<A, const SIZE: usize> Sync for Chunk<A, SIZE> where
A: Sync,
A: Sync,
impl<A, const SIZE: usize> Unpin for Chunk<A, SIZE> where
A: Unpin,
A: Unpin,
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,
pub 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.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,