The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Wasm::Wasmer::Memory - WebAssembly memory

SYNOPSIS

    my $store = Wasm::Wasmer::Store->new();

    my $life = $store->create_memory( initial => 2 );

DESCRIPTION

This class represents WebAssembly memory imports & exports.

This class subclasses Wasm::Wasmer::Extern.

CONSTANTS

PAGE_SIZE

The size, in bytes, of each page.

METHODS

$bytes = OBJ->get( [ $OFFSET [, $LENGTH ] ] )

Retrieves the memory’s contents as a byte string.

$OFFSET and $LENGTH behave as they do with "substr" in perlfunc, but negative $LENGTH is currently unsupported.

To retrieve the entire buffer:

    $memory->get()

To retrieve the entire buffer except the first 9 bytes:

    $memory->get(9)

To retrieve a 5-byte string starting at offset 8:

    $memory->get(8, 5);

$obj = OBJ->set( $NEW_BYTES [, $OFFSET] )

Splices a new byte sequence into the memory, starting at $OFFSET (0 by default). Returns OBJ.

Throws if there’s a range error or if $NEW_BYTES contains any >255 code points.

$obj = OBJ->grow( $DELTA )

Grows the memory by $DELTA (nonnegative) pages, or throws an error if that grow operation fails. Returns OBJ.

($initial, $maximum) = OBJ->limits()

Returns the memory’s lower & upper page-count limits.

$pages = OBJ->size()

Returns the memory’s current size in pages. (The byte length is $pages * Wasm::Wasmer::PAGE_SIZE.)