Wasm::Wasmtime::Memory - Wasmtime memory class
version 0.23
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
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.
my $memory = Wasm::Wasmtime::Memory->new( $store, # Wasm::Wasmtime::Store $memorytype, # Wasm::Wasmtime::MemoryType );
Creates a new memory object.
my $memorytype = $memory->type;
Returns the Wasm::Wasmtime::MemoryType object for this memory object.
my $pointer = $memory->data;
Returns a pointer to the start of the memory.
my $size = $memory->data_size;
Returns the current size of the memory in bytes.
my $size = $memory->size;
Returns the current size of the memory in pages.
my $bool = $memory->grow($delta);
Tries to increase the page size by the given $delta
. Returns true on success, false otherwise.
Graham Ollis <plicease@cpan.org>
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.