pub struct SCAllocator<'a, P: AllocablePage> { /* private fields */ }
Expand description

A slab allocator allocates elements of a fixed size.

It maintains three internal lists of objects that implement AllocablePage 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.

If an allocation returns OutOfMemory a client using SCAllocator can refill it using the refill function.

Implementations

Create a new SCAllocator.

Returns the maximum supported object size of this allocator.

Refill the SCAllocator

Safety

ObjectPage needs to be empty etc.

Allocates a block of memory descriped by layout.

Returns a pointer to a valid region of memory or an AllocationError.

The function may also move around pages between lists (empty -> partial or partial -> full).

Deallocates a previously allocated ptr described by Layout.

May return an error in case an invalid layout is provided. The function may also move internal slab pages between lists partial -> empty or full -> partial lists.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.