[−][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, Region}; use std::{ alloc::{AllocRef, Layout}, mem::MaybeUninit, }; let mut data = [MaybeUninit::new(0); 64]; let mut alloc = Chunk::<_, 64>(Region::new(&mut data)); let ptr = alloc.alloc(Layout::new::<[u8; 16]>())?; assert_eq!(ptr.len() % 32, 0); assert!(ptr.len() >= 32);
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)] use alloc_compose::ReallocInPlace; let len = unsafe { alloc.grow_in_place(ptr.as_non_null_ptr(), Layout::new::<[u8; 16]>(), 24)? }; assert_eq!(len % 32, 0); assert!(len >= 32);
Trait Implementations
impl<A: AllocAll, const SIZE: usize> AllocAll for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo,
[src]
Self: SizeIsPowerOfTwo,
fn alloc_all(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr>
[src]
fn alloc_all_zeroed(
&mut self,
layout: Layout
) -> Result<NonNull<[u8]>, AllocErr>
[src]
&mut self,
layout: Layout
) -> Result<NonNull<[u8]>, AllocErr>
fn dealloc_all(&mut self)
[src]
fn capacity(&self) -> usize
[src]
fn capacity_left(&self) -> usize
[src]
fn is_empty(&self) -> bool
[src]
fn is_full(&self) -> bool
[src]
impl<A: AllocRef, const SIZE: usize> AllocRef for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo,
[src]
Self: SizeIsPowerOfTwo,
fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr>
[src]
fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr>
[src]
unsafe fn grow(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<NonNull<[u8]>, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<NonNull<[u8]>, AllocErr>
unsafe fn grow_zeroed(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<NonNull<[u8]>, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<NonNull<[u8]>, AllocErr>
unsafe fn shrink(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<NonNull<[u8]>, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<NonNull<[u8]>, AllocErr>
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout)
[src]
fn by_ref(&mut self) -> &mut Self
[src]
impl<A: Clone, const SIZE: usize> Clone for Chunk<A, SIZE>
[src]
fn clone(&self) -> Chunk<A, SIZE>
[src]
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]
impl<A: ReallocInPlace, const SIZE: usize> ReallocInPlace for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo,
[src]
Self: SizeIsPowerOfTwo,
unsafe fn grow_in_place(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
unsafe fn grow_in_place_zeroed(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
unsafe fn shrink_in_place(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
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,
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>,