Skip to main content

BumpAllocatorCoreScope

Trait BumpAllocatorCoreScope 

Source
pub unsafe trait BumpAllocatorCoreScope<'a>: BumpAllocatorCore { }
Expand description

A bump allocator scope.

This is a BumpAllocatorCore which can make allocations that outlive itself. Specifically, its allocations live for the lifetime 'a.

§Safety

This trait must only be implemented when allocations live for 'a. For example this function must be sound:

use bump_scope::traits::BumpAllocatorCoreScope;
use core::alloc::Layout;

fn allocate_zeroed_bytes<'a>(allocator: impl BumpAllocatorCoreScope<'a>, len: usize) -> &'a [u8] {
    let layout = Layout::array::<u8>(len).unwrap();
    let ptr = allocator.allocate_zeroed(layout).unwrap();
    unsafe { ptr.as_ref() }
}

Trait Implementations§

Source§

impl BumpAllocatorTyped for dyn BumpAllocatorCoreScope<'_> + '_

Source§

type TypedStats<'b> = AnyStats<'b> where Self: 'b

The type returned by the stats method.
Source§

fn typed_stats(&self) -> AnyStats<'_>

Returns a type which provides statistics about the memory usage of the bump allocator.
Source§

fn allocate_layout(&self, layout: Layout) -> NonNull<u8>

A specialized version of allocate. Read more
Source§

fn try_allocate_layout(&self, layout: Layout) -> Result<NonNull<u8>, AllocError>

A specialized version of allocate. Read more
Source§

fn allocate_sized<T>(&self) -> NonNull<T>

A specialized version of allocate. Read more
Source§

fn try_allocate_sized<T>(&self) -> Result<NonNull<T>, AllocError>

A specialized version of allocate. Read more
Source§

fn allocate_slice<T>(&self, len: usize) -> NonNull<T>

A specialized version of allocate. Read more
Source§

fn try_allocate_slice<T>(&self, len: usize) -> Result<NonNull<T>, AllocError>

A specialized version of allocate. Read more
Source§

fn allocate_slice_for<T>(&self, slice: &[T]) -> NonNull<T>

A specialized version of allocate. Read more
Source§

fn try_allocate_slice_for<T>( &self, slice: &[T], ) -> Result<NonNull<T>, AllocError>

A specialized version of allocate. Read more
Source§

unsafe fn shrink_slice<T>( &self, ptr: NonNull<T>, old_len: usize, new_len: usize, ) -> Option<NonNull<T>>

A specialized version of shrink. Read more
Source§

fn prepare_slice_allocation<T>(&self, len: usize) -> NonNull<[T]>

A specialized version of prepare_allocation. Read more
Source§

fn try_prepare_slice_allocation<T>( &self, len: usize, ) -> Result<NonNull<[T]>, AllocError>

A specialized version of prepare_allocation. Read more
Source§

unsafe fn allocate_prepared_slice<T>( &self, ptr: NonNull<T>, len: usize, cap: usize, ) -> NonNull<[T]>

A specialized version of allocate_prepared. Read more
Source§

fn prepare_slice_allocation_rev<T>(&self, len: usize) -> (NonNull<T>, usize)

A specialized version of prepare_allocation_rev. Read more
Source§

fn try_prepare_slice_allocation_rev<T>( &self, len: usize, ) -> Result<(NonNull<T>, usize), AllocError>

A specialized version of prepare_allocation_rev. Read more
Source§

unsafe fn allocate_prepared_slice_rev<T>( &self, ptr: NonNull<T>, len: usize, cap: usize, ) -> NonNull<[T]>

A specialized version of allocate_prepared_rev. Read more
Source§

fn reserve(&self, additional: usize)

Reserves capacity for at least additional more bytes to be bump allocated. The bump allocator may reserve more space to avoid frequent reallocations. After calling reserve, self.stats().remaining() will be greater than or equal to additional. Does nothing if the capacity is already sufficient. Read more
Source§

fn try_reserve(&self, additional: usize) -> Result<(), AllocError>

Reserves capacity for at least additional more bytes to be bump allocated. The bump allocator may reserve more space to avoid frequent reallocations. After calling reserve, self.stats().remaining() will be greater than or equal to additional. Does nothing if the capacity is already sufficient. Read more
Source§

fn dealloc<T: ?Sized>(&self, boxed: BumpBox<'_, T>)

Drops an allocated value and attempts to free its memory. Read more

Implementations on Foreign Types§

Source§

impl<'a, B: BumpAllocatorCoreScope<'a> + ?Sized> BumpAllocatorCoreScope<'a> for &B

Source§

impl<'a, B: BumpAllocatorCoreScope<'a> + ?Sized> BumpAllocatorCoreScope<'a> for &mut B

Implementors§