pub struct Memory { /* private fields */ }
Expand description
Defines a WebAssembly memory instance, which is a linear memory described by its type. Each memory instance consists of a vector of bytes and an optional maximum size, and its size is a multiple of the WebAssembly page size (64KiB of each page).
Implementations§
Source§impl Memory
impl Memory
Sourcepub fn create(ty: &MemoryType) -> WasmEdgeResult<Self>
pub fn create(ty: &MemoryType) -> WasmEdgeResult<Self>
Create a new Memory to be associated with the given capacity limit.
§Arguments
ty
- The type of the new Memory instance.
§Errors
- If fail to create the memory instance, then WasmEdgeError::Mem(MemError::Create) is returned.
Sourcepub fn ty(&self) -> WasmEdgeResult<MemoryType>
pub fn ty(&self) -> WasmEdgeResult<MemoryType>
Sourcepub unsafe fn data_pointer(
&self,
offset: u32,
len: u32,
) -> WasmEdgeResult<*const u8>
pub unsafe fn data_pointer( &self, offset: u32, len: u32, ) -> WasmEdgeResult<*const u8>
Returns the const data pointer to the Memory.
§Arguments
-
offset
- The data start offset in the Memory. -
len
- The requested data length. If the size ofoffset
+len
is larger than the data size in the Memory
§Errors
If fail to get the data pointer, then an error is returned.
§Safety
The lifetime of the returned pointer must not exceed that of the object itself.
Sourcepub unsafe fn data_pointer_mut(
&mut self,
offset: u32,
len: u32,
) -> WasmEdgeResult<*mut u8>
pub unsafe fn data_pointer_mut( &mut self, offset: u32, len: u32, ) -> WasmEdgeResult<*mut u8>
Returns the data pointer to the Memory.
§Arguments
-
offset
- The data start offset in the Memory. -
len
- The requested data length. If the size ofoffset
+len
is larger than the data size in the Memory
§Errors
If fail to get the data pointer, then an error is returned.
§Safety
The lifetime of the returned pointer must not exceed that of the object itself.
Sourcepub fn size(&self) -> u32
pub fn size(&self) -> u32
Returns the size, in WebAssembly pages (64 KiB of each page), of this wasm memory.
Sourcepub fn grow(&mut self, count: u32) -> WasmEdgeResult<()>
pub fn grow(&mut self, count: u32) -> WasmEdgeResult<()>
Sourcepub unsafe fn as_ptr(&self) -> *const WasmEdge_MemoryInstanceContext
pub unsafe fn as_ptr(&self) -> *const WasmEdge_MemoryInstanceContext
§Safety
Provides a raw pointer to the inner memory context. The lifetime of the returned pointer must not exceed that of the object itself.
Source§impl Memory
impl Memory
pub fn get_ref<T: Sized>(&self, offset: usize) -> Option<&T>
pub fn slice<T: Sized>(&self, offset: usize, len: usize) -> Option<&[T]>
pub fn get_ref_mut<T: Sized>(&mut self, offset: usize) -> Option<&mut T>
pub fn mut_slice<T: Sized>(&self, offset: usize, len: usize) -> Option<&mut [T]>
pub fn write<T: Sized>(&mut self, offset: usize, data: T) -> Option<()>
Trait Implementations§
Source§impl Memory for Memory
Available on crate feature async
and Linux only.
impl Memory for Memory
async
and Linux only.