[][src]Struct slabmalloc::SCAllocator

pub struct SCAllocator<'a> { /* fields omitted */ }

A slab allocator allocates elements of a fixed size.

It has a 3 lists of ObjectPages from which it can allocate memory.

  • empty_slabs: Is a list of pages that the SCAllocator maintains, but has 0 allocations in them, these can be given back to a requestor in case of reclamation.
  • slabs: A list of pages partially allocated and still have room for more.
  • full_slabs: A list of pages that are completely allocated.

On allocation we allocate memory from slabs, however if the list is empty we try to reclaim a page from empty_slabs before we return with an out-of-memory error. If a page becomes full after the allocation we move it from slabs to full_slabs.

Similarly, on dealloaction we might move a page from full_slabs to slabs or from slabs to empty_slabs after we deallocated an object.

Methods

impl<'a> SCAllocator<'a>[src]

pub const fn new(size: usize) -> SCAllocator<'a>[src]

Create a new SCAllocator.

pub fn size(&self) -> usize[src]

Return object size of this allocator.

pub unsafe fn refill(&mut self, page: &'a mut ObjectPage<'a>)[src]

Refill the SCAllocator

Safety

ObjectPage needs to be empty etc.

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

Allocates a block of memory with respect to alignment.

In case of failure will try to grow the slab allocator by requesting additional pages and re-try the allocation once more before we give up.

pub fn deallocate(
    &mut self,
    ptr: NonNull<u8>,
    layout: Layout
) -> Result<(), AllocationError>
[src]

Deallocates a previously allocated block.

Auto Trait Implementations

impl<'a> Unpin for SCAllocator<'a>

impl<'a> Send for SCAllocator<'a>

impl<'a> Sync for SCAllocator<'a>

impl<'a> !UnwindSafe for SCAllocator<'a>

impl<'a> RefUnwindSafe for SCAllocator<'a>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]