[−][src]Function wasmer_runtime_c_api::instance::wasmer_instance_context_memory
#[no_mangle] pub extern "C" fn wasmer_instance_context_memory(
ctx: *const wasmer_instance_context_t,
_memory_idx: u32
) -> *const wasmer_memory_t
Gets the memory_idx
th memory of the instance.
Note that the index is always 0
until multiple memories are supported.
This function is mostly used inside host functions (aka imported functions) to read the instance memory.
Example of a host function that reads and prints a string based on a pointer and a length:
void print_string(const wasmer_instance_context_t *context, int32_t pointer, int32_t length) {
// Get the 0th memory.
const wasmer_memory_t *memory = wasmer_instance_context_memory(context, 0);
// Get the memory data as a pointer.
uint8_t *memory_bytes = wasmer_memory_data(memory);
// Print what we assumed to be a string!
printf("%.*s", length, memory_bytes + pointer);
}