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§

Initializes a MemoryManager with the given memory.

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

Returns the memory associated with the given ID.

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.