Trait hal::memory::FrameAllocator

source ·
pub trait FrameAllocator<S>
where S: FrameSize,
{ // Required methods fn allocate_n(&self, n: usize) -> Range<Frame<S>>; fn free_n(&self, start: Frame<S>, n: usize); // Provided method fn allocate(&self) -> Frame<S> { ... } }
Expand description

FrameAllocator is used to interact with a physical memory manager in a platform-independent way. Methods on FrameAllocator take &self and so are expected to use interior-mutability through a type such as Mutex to ensure safe access. This allows structures to store a reference to the allocator, and deallocate memory when they’re dropped.

A FrameAllocator is defined for a specific FrameSize, but multiple implementations of FrameAllocator (each with a different frame size) can be used for allocators that aren’t tied to a specific block size.

Required Methods§

source

fn allocate_n(&self, n: usize) -> Range<Frame<S>>

Allocate n contiguous Frames.

source

fn free_n(&self, start: Frame<S>, n: usize)

Free n frames that were previously allocated by this allocator.

Provided Methods§

source

fn allocate(&self) -> Frame<S>

Allocate a Frame.

By default, this calls allocate_n(1), but can be overridden if an allocator can provide a more efficient method for allocating single frames.

Implementors§