NAME

Wasm::Wasmtime::Memory - Wasmtime memory class

VERSION

version 0.23

SYNOPSIS

use Wasm::Wasmtime;
use PeekPoke::FFI qw( poke );

my $store = Wasm::Wasmtime::Store->new;

# create a new memory object with a minumum
# of 3 pages and maximum of 9
my $memory = Wasm::Wasmtime::Memory->new(
  $store,
  Wasm::Wasmtime::MemoryType->new([3,9]),
);

poke($memory->data + 10, 42);                   # store the byte 42 at offset
                                                # 10 inside the data region

printf "data_size = %x\n", $memory->data_size;  # 30000
printf "size      = %d\n", $memory->size;       # 3

$memory->grow(4);                               # increase data region by 4 pages

printf "data_size = %x\n", $memory->data_size;  # 70000
printf "size      = %d\n", $memory->size;       # 7

DESCRIPTION

WARNING: WebAssembly and Wasmtime are a moving target and the interface for these modules is under active development. Use with caution.

This class represents a WebAssembly memory object.

CONSTRUCTOR

new

my $memory = Wasm::Wasmtime::Memory->new(
  $store,      # Wasm::Wasmtime::Store
  $memorytype, # Wasm::Wasmtime::MemoryType
);

Creates a new memory object.

METHODS

type

my $memorytype = $memory->type;

Returns the Wasm::Wasmtime::MemoryType object for this memory object.

data

my $pointer = $memory->data;

Returns a pointer to the start of the memory.

data_size

my $size = $memory->data_size;

Returns the current size of the memory in bytes.

size

my $size = $memory->size;

Returns the current size of the memory in pages.

grow

my $bool = $memory->grow($delta);

Tries to increase the page size by the given $delta. Returns true on success, false otherwise.

SEE ALSO

Wasm
Wasm::Wasmtime

AUTHOR

Graham Ollis <plicease@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020-2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.