[−][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::{region::Region, Fallback, Owns}; 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,
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 dealloc(&self, ptr: NonNull<u8>, layout: Layout)
[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 fn by_ref(&self) -> &Self
[src]
impl<Primary: Clone, Secondary: Clone> Clone for Fallback<Primary, Secondary>
[src]
pub fn clone(&self) -> Fallback<Primary, Secondary>
[src]
pub 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,
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>,