pub struct MemoryManager<M: Memory> { /* private fields */ }
Expand description

A memory manager simulates multiple memories within a single memory.

The memory manager can return up to 255 unique instances of VirtualMemory, and each can be used independently and can grow up to the bounds of the underlying memory.

By default, the memory manager divides the memory into “buckets” of 128 pages. Each VirtualMemory is internally represented as a list of buckets. Buckets of different memories can be interleaved, but the VirtualMemory interface gives the illusion of a continuous address space.

Because a VirtualMemory is a list of buckets, this implies that internally it grows one bucket at a time.

The first page of the memory is reserved for the memory manager’s own state. The layout for this state is as follows:

§V1 layout

-------------------------------------------------- <- Address 0
Magic "MGR"                           ↕ 3 bytes
--------------------------------------------------
Layout version                        ↕ 1 byte
--------------------------------------------------
Number of allocated buckets           ↕ 2 bytes
--------------------------------------------------
Bucket size (in pages) = N            ↕ 2 bytes
--------------------------------------------------
Reserved space                        ↕ 32 bytes
--------------------------------------------------
Size of memory 0 (in pages)           ↕ 8 bytes
--------------------------------------------------
Size of memory 1 (in pages)           ↕ 8 bytes
--------------------------------------------------
...
--------------------------------------------------
Size of memory 254 (in pages)         ↕ 8 bytes
-------------------------------------------------- <- Bucket allocations
Bucket 1                              ↕ 1 byte        (1 byte indicating which memory owns it)
--------------------------------------------------
Bucket 2                              ↕ 1 byte
--------------------------------------------------
...
--------------------------------------------------
Bucket `MAX_NUM_BUCKETS`              ↕ 1 byte
--------------------------------------------------
Unallocated space                     ↕ 30'688 bytes
-------------------------------------------------- <- Buckets (Page 1)
Bucket 1                              ↕ N pages
-------------------------------------------------- <- Page N + 1
Bucket 2                              ↕ N pages
--------------------------------------------------
...
-------------------------------------------------- <- Page ((MAX_NUM_BUCKETS - 1) * N + 1)
Bucket MAX_NUM_BUCKETS                ↕ N pages

Implementations§

source§

impl<M: Memory> MemoryManager<M>

source

pub fn init(memory: M) -> Self

Initializes a MemoryManager with the given memory.

source

pub fn init_with_bucket_size(memory: M, bucket_size_in_pages: u16) -> Self

Initializes a MemoryManager with the given memory and bucket size in pages.

source

pub fn get(&self, id: MemoryId) -> VirtualMemory<M>

Returns the memory associated with the given ID.

source

pub fn into_memory(self) -> Option<M>

Returns the underlying memory.

§Returns
  • The underlying memory, if there is exactly one strong reference to the memory manager. Please see Rc::try_unwrap for more details.
  • None otherwise.

Auto Trait Implementations§

§

impl<M> Freeze for MemoryManager<M>

§

impl<M> !RefUnwindSafe for MemoryManager<M>

§

impl<M> !Send for MemoryManager<M>

§

impl<M> !Sync for MemoryManager<M>

§

impl<M> Unpin for MemoryManager<M>

§

impl<M> !UnwindSafe for MemoryManager<M>

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>,

§

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>,

§

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.