[−][src]Struct alloc_compose::FallbackAlloc
An allocator equivalent of an "or" operator in algebra.
An allocation request is first attempted with the Primary
allocator. If that fails, the
request is forwarded to the Fallback
allocator. All other requests are dispatched
appropriately to one of the two allocators.
A FallbackAlloc
is useful for fast, special-purpose allocators backed up by general-purpose
allocators like Global
or System
.
Example
#![feature(allocator_api)] use alloc_compose::{FallbackAlloc, Owns, Region}; use std::alloc::{AllocInit, AllocRef, Layout, System}; let mut data = [0; 32]; let mut alloc = FallbackAlloc { primary: Region::new(&mut data), fallback: System, }; let small_memory = alloc.alloc(Layout::new::<u32>(), AllocInit::Uninitialized)?; let big_memory = alloc.alloc(Layout::new::<[u32; 64]>(), AllocInit::Uninitialized)?; assert!(alloc.primary.owns(small_memory)); assert!(!alloc.primary.owns(big_memory)); unsafe { // `big_memory` was allocated from `System`, we can dealloc it directly System.dealloc(big_memory.ptr, Layout::new::<[u32; 64]>()); alloc.dealloc(small_memory.ptr, Layout::new::<u32>()); };
Fields
primary: Primary
The primary allocator
fallback: Fallback
The fallback allocator
Trait Implementations
impl<Primary, Fallback> AllocRef for FallbackAlloc<Primary, Fallback> where
Primary: AllocRef + Owns,
Fallback: AllocRef,
[src]
Primary: AllocRef + Owns,
Fallback: AllocRef,
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<Primary: Clone, Fallback: Clone> Clone for FallbackAlloc<Primary, Fallback>
[src]
fn clone(&self) -> FallbackAlloc<Primary, Fallback>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Primary: Copy, Fallback: Copy> Copy for FallbackAlloc<Primary, Fallback>
[src]
impl<Primary: Debug, Fallback: Debug> Debug for FallbackAlloc<Primary, Fallback>
[src]
impl<Primary, Fallback> Owns for FallbackAlloc<Primary, Fallback> where
Primary: Owns,
Fallback: Owns,
[src]
Primary: Owns,
Fallback: Owns,
fn owns(&self, memory: MemoryBlock) -> bool
[src]
Auto Trait Implementations
impl<Primary, Fallback> Send for FallbackAlloc<Primary, Fallback> where
Fallback: Send,
Primary: Send,
Fallback: Send,
Primary: Send,
impl<Primary, Fallback> Sync for FallbackAlloc<Primary, Fallback> where
Fallback: Sync,
Primary: Sync,
Fallback: Sync,
Primary: Sync,
impl<Primary, Fallback> Unpin for FallbackAlloc<Primary, Fallback> where
Fallback: Unpin,
Primary: Unpin,
Fallback: Unpin,
Primary: 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>,