[−][src]Struct alloc_compose::Chunk
Allocate memory with a multiple size of the provided chunk size.
Examples
#![feature(allocator_api)] use alloc_compose::Chunk; use std::alloc::{AllocInit, AllocRef, Layout, System}; let mut data = [0; 64]; let mut alloc = Chunk::<_, 64>(System); let memory = alloc.alloc(Layout::new::<[u8; 16]>(), AllocInit::Uninitialized)?; assert_eq!(memory.size % 32, 0); assert!(memory.size >= 32);
When growing or shrinking the memory, Chunk
will try to alter
the memory in place before delegating to the underlying allocator.
use std::alloc::ReallocPlacement; let memory = unsafe { alloc.grow( memory.ptr, Layout::new::<[u8; 16]>(), 24, ReallocPlacement::InPlace, AllocInit::Uninitialized, )? }; assert_eq!(memory.size % 32, 0); assert!(memory.size >= 32);
Trait Implementations
impl<A: AllocRef, const SIZE: usize> AllocRef for Chunk<A, SIZE>
[src]
fn alloc(
&mut self,
layout: Layout,
init: AllocInit
) -> Result<MemoryBlock, AllocErr>
[src]
&mut self,
layout: Layout,
init: AllocInit
) -> Result<MemoryBlock, AllocErr>
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout)
[src]
unsafe fn grow(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
placement: ReallocPlacement,
init: AllocInit
) -> Result<MemoryBlock, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
placement: ReallocPlacement,
init: AllocInit
) -> Result<MemoryBlock, AllocErr>
unsafe fn shrink(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
placement: ReallocPlacement
) -> Result<MemoryBlock, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
placement: ReallocPlacement
) -> Result<MemoryBlock, AllocErr>
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>
[src]
fn owns(&self, memory: MemoryBlock) -> bool
[src]
impl<A: PartialEq, const SIZE: usize> PartialEq<Chunk<A, SIZE>> for Chunk<A, SIZE>
[src]
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<const SIZE: usize, A> Send for Chunk<A, SIZE> where
A: Send,
A: Send,
impl<const SIZE: usize, A> Sync for Chunk<A, SIZE> where
A: Sync,
A: Sync,
impl<const SIZE: usize, A> 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>,