Struct wasmtime_runtime::Memory
source · [−]pub struct Memory(_);
Expand description
Representation of a runtime wasm linear memory.
Implementations
sourceimpl Memory
impl Memory
sourcepub fn new_dynamic(
plan: &MemoryPlan,
creator: &dyn RuntimeMemoryCreator,
store: &mut dyn Store,
memory_image: Option<&Arc<MemoryImage>>
) -> Result<Self>
pub fn new_dynamic(
plan: &MemoryPlan,
creator: &dyn RuntimeMemoryCreator,
store: &mut dyn Store,
memory_image: Option<&Arc<MemoryImage>>
) -> Result<Self>
Create a new dynamic (movable) memory instance for the specified plan.
sourcepub fn new_static(
plan: &MemoryPlan,
base: &'static mut [u8],
make_accessible: Option<fn(_: *mut u8, _: usize) -> Result<()>>,
memory_image: Option<MemoryImageSlot>,
store: &mut dyn Store
) -> Result<Self>
pub fn new_static(
plan: &MemoryPlan,
base: &'static mut [u8],
make_accessible: Option<fn(_: *mut u8, _: usize) -> Result<()>>,
memory_image: Option<MemoryImageSlot>,
store: &mut dyn Store
) -> Result<Self>
Create a new static (immovable) memory instance for the specified plan.
sourcepub fn maximum_byte_size(&self) -> Option<usize>
pub fn maximum_byte_size(&self) -> Option<usize>
Returns the maximum number of pages the memory can grow to at runtime.
Returns None
if the memory is unbounded.
The runtime maximum may not be equal to the maximum from the linear memory’s Wasm type when it is being constrained by an instance allocator.
sourcepub unsafe fn grow(
&mut self,
delta_pages: u64,
store: Option<&mut dyn Store>
) -> Result<Option<usize>, Error>
pub unsafe fn grow(
&mut self,
delta_pages: u64,
store: Option<&mut dyn Store>
) -> Result<Option<usize>, Error>
Grow memory by the specified amount of wasm pages.
Returns None
if memory can’t be grown by the specified amount
of wasm pages. Returns Some
with the old size of memory, in bytes, on
successful growth.
Safety
Resizing the memory can reallocate the memory buffer for dynamic memories.
An instance’s VMContext
may have pointers to the memory’s base and will
need to be fixed up after growing the memory.
Generally, prefer using InstanceHandle::memory_grow
, which encapsulates
this unsafety.
Ensure that the provided Store is not used to get access any Memory which lives inside it.
sourcepub fn vmmemory(&mut self) -> VMMemoryDefinition
pub fn vmmemory(&mut self) -> VMMemoryDefinition
Return a VMMemoryDefinition
for exposing the memory to compiled wasm code.
sourcepub fn is_static(&mut self) -> bool
pub fn is_static(&mut self) -> bool
Check if the inner implementation of Memory
is a memory created with
Memory::new_static()
.
sourcepub fn unwrap_static_image(self) -> Option<MemoryImageSlot>
pub fn unwrap_static_image(self) -> Option<MemoryImageSlot>
Consume the memory, returning its MemoryImageSlot
if any is present.
The image should only be present for a subset of memories created with
Memory::new_static()
.
If the Memory is a SharedMemory, unwrap it and return a clone to that shared memory.
Auto Trait Implementations
impl !RefUnwindSafe for Memory
impl Send for Memory
impl Sync for Memory
impl Unpin for Memory
impl !UnwindSafe for Memory
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more