[−][src]Struct alloc_compose::Fallback
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 Fallback
is useful for fast, special-purpose allocators backed up by general-purpose
allocators like Global
or System
.
Example
#![feature(allocator_api, slice_ptr_get)] use alloc_compose::{Fallback, Owns, Region}; use std::{ alloc::{AllocRef, Layout, System}, mem::MaybeUninit, }; let mut data = [MaybeUninit::new(0); 32]; let mut alloc = Fallback { primary: Region::new(&mut data), secondary: System, }; let small_memory = alloc.alloc(Layout::new::<u32>())?; let big_memory = alloc.alloc(Layout::new::<[u32; 64]>())?; 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.as_non_null_ptr(), Layout::new::<[u32; 64]>()); alloc.dealloc(small_memory.as_non_null_ptr(), Layout::new::<u32>()); };
Fields
primary: Primary
The primary allocator
secondary: Secondary
The fallback allocator
Trait Implementations
impl<Primary, Secondary> AllocRef for Fallback<Primary, Secondary> where
Primary: AllocRef + Owns,
Secondary: AllocRef,
[src]
Primary: AllocRef + Owns,
Secondary: AllocRef,
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 dealloc(&mut self, ptr: NonNull<u8>, layout: Layout)
[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>
fn by_ref(&mut self) -> &mut Self
[src]
impl<Primary: Clone, Secondary: Clone> Clone for Fallback<Primary, Secondary>
[src]
fn clone(&self) -> Fallback<Primary, Secondary>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Primary: Copy, Secondary: Copy> Copy for Fallback<Primary, Secondary>
[src]
impl<Primary: Debug, Secondary: Debug> Debug for Fallback<Primary, Secondary>
[src]
impl<Primary, Secondary> Owns for Fallback<Primary, Secondary> where
Primary: Owns,
Secondary: Owns,
[src]
Primary: Owns,
Secondary: Owns,
Auto Trait Implementations
impl<Primary, Secondary> Send for Fallback<Primary, Secondary> where
Primary: Send,
Secondary: Send,
Primary: Send,
Secondary: Send,
impl<Primary, Secondary> Sync for Fallback<Primary, Secondary> where
Primary: Sync,
Secondary: Sync,
Primary: Sync,
Secondary: Sync,
impl<Primary, Secondary> Unpin for Fallback<Primary, Secondary> where
Primary: Unpin,
Secondary: Unpin,
Primary: Unpin,
Secondary: 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>,