The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Wasm::Memory - Interface to WebAssembly Memory

VERSION

version 0.11

SYNOPSIS

 use PeekPoke::FFI qw( peek poke );
 use Wasm
   -api => 0,
   -wat => q{
     (module
       (memory (export "memory") 3 9)
     )
   }
 ;
 
 # $memory isa Wasm::Memory
 poke($memory->address + 10, 42);                # store the byte 42 at offset
                                                 # 10 inside the data region
 
 my($current, $min, $max) = $memory->limits;
 printf "size    = %x\n", $memory->size;         # 30000
 printf "current = %d\n", $current;              # 3
 printf "min     = %d\n", $min;                  # 3
 printf "max     = %d\n", $max;                  # 9
 
 $memory->grow(4);                               # increase data region by 4 pages
 
 ($current, $min, $max) = $memory->limits;
 printf "size    = %x\n", $memory->size;         # 70000
 printf "current = %d\n", $current;              # 7
 printf "min     = %d\n", $min;                  # 3
 printf "max     = %d\n", $max;                  # 9

DESCRIPTION

This class represents a region of memory exported from a WebAssembly module. A Wasm::Memory instance is automatically imported into Perl space for each WebAssembly memory region with the same name.

METHODS

address

 my $pointer = $memory->address;

Returns an opaque pointer to the start of memory.

size

 my $size = $memory->size;

Returns the size of the memory in bytes.

limits

 my($current, $min, $max) = $memory->limits;

Returns the current memory limit, the minimum and maximum. All sizes are in pages.

grow

 $memory->grow($count);

Grown the memory region by $count pages.

SEE ALSO

Wasm

AUTHOR

Graham Ollis <plicease@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 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.