[][src]Module fluence_sdk::memory

Basic functions for dealing with Wasm memory.

This module contains functions for initializing and manipulating memory.

Modules

errors

Contains definitions for memory errors.

Constants

STR_LEN_BYTES

Count of bytes that a string length representation in memory occupy. See write_str_to_mem method.

Functions

alloc

Allocates memory area of specified size and returns its address. Actually is just a wrapper for GlobalAlloc::alloc.

dealloc

Deallocates memory area for current memory pointer and size. Actually is just a wrapper for GlobalAlloc::dealloc.

deref_str

Builds Rust string from the pointer and the length. Bytes copying doesn't occur, new String just wraps bytes around. Memory will be deallocated when the String will be dropped.

read_str_from_fat_ptr

Reads Rust String from the raw memory. This operation is opposite of write_str_to_mem. Reads from the raw memory a string length as first STR_LEN_BYTES bytes and then reads string for this length. Deallocates first STR_LEN_BYTES bytes that corresponded string length and wraps the rest bytes into a Rust string.

write_str_to_mem

Writes Rust string to the memory directly as string length and byte array. This method allocates new 'STR_LEN_BYTES + str.len()' bytes and writes the length of the string as first STR_LEN_BYTES bytes and then writes copy of 'str' after 'length' as a rest of the bytes.

Type Definitions

MemResult

Result type for this module.