PoolAllocator

Struct PoolAllocator 

Source
pub struct PoolAllocator { /* private fields */ }

Implementations§

Source§

impl PoolAllocator

Source

pub fn number_of_buckets(&self) -> u32

Source

pub fn bucket_size(&self) -> usize

Source

pub fn size(&self) -> usize

Source

pub fn start_address(&self) -> usize

Source

pub fn max_alignment(&self) -> usize

Source

pub unsafe fn deallocate_bucket(&self, ptr: NonNull<u8>)

Releases an previously allocated bucket of memory.

§Safety
Source

pub unsafe fn new_uninit( bucket_layout: Layout, ptr: NonNull<u8>, size: usize, ) -> Self

§Safety
  • ptr must point to a piece of memory of length size
  • before any other method can be called PoolAllocator::init() must be called once
Source

pub unsafe fn init<Allocator: BaseAllocator>( &mut self, allocator: &Allocator, ) -> Result<(), AllocationError>

§Safety
  • must be called exactly once before any other method can be called
Source

pub fn memory_size(bucket_layout: Layout, size: usize) -> usize

Trait Implementations§

Source§

impl Allocator for PoolAllocator

Source§

unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocationGrowError>

always returns the input ptr on success but with an increased size

Source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocationShrinkError>

Decreases the size of an previously allocated chunk of memory. If the size increases it fails. Read more
Source§

unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocationGrowError>

Increases the size of an previously allocated chunk of memory or allocates a new chunk with the provided properties. If the chunk can be resized only the difference in size will be zeroed. It returns a failure when the size decreases. Read more
Source§

impl BaseAllocator for PoolAllocator

Source§

fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocationError>

Allocates a memory chunk with the properties provided in layout and either returns a slice or an allocation error on failure.
Source§

unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout)

Releases an previously allocated chunk of memory. Read more
Source§

fn allocate_zeroed( &self, layout: Layout, ) -> Result<NonNull<[u8]>, AllocationError>

Allocates a memory chunk with the properties provided in layout and zeroes the memory On success it returns a slice or an allocation error on failure.
Source§

impl Debug for PoolAllocator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.