Skip to content

Latest commit

 

History

History
59 lines (36 loc) · 1.46 KB

memory.grow.md

File metadata and controls

59 lines (36 loc) · 1.46 KB

memory.grow (request more memory)

Requests more memory be allocated to the WASM instance 1.

Takes one operand from the stack, an i32 representing the number of pages to request 1; Each page is defined as 64KiB 2.

Returns one result to the stack, an i32 representing the previous total size of memory in pages, or -1 if the operation failed 1.

$$ \mathsf{memory.grow} \enspace ( pages: \mathsf{i32} ) \to \begin{cases} -1_\mathsf{i32} &\text{if failed to grow} \\ \ge 0_\mathsf{i32} &\text{otherwise} \end{cases} $$

Instructions

Opcode Instruction Stack Arity
0x40 memory.grow $[ \mathsf{i32} ] \to [ \mathsf{i32} ]$

WAT Examples

Requesting more memory

;; Places 2 on the stack
i32.const 2

;; Takes one value off of the stack (2), and requests
;; that many additional pages of memory
memory.grow

;; Places -1 on the stack
i32.const -1

;; Takes two values off of the stack (the result from
;; memory.grow and -1) and compares them
i32.eq

if
  ;; If the two values are equal, the instance failed
  ;; to get more memory
end

References

WebAssembly Core Specification

Footnotes

  1. Structure, Memory Instructions - https://www.w3.org/TR/wasm-core-2/syntax/instructions.html#memory-instructions 2 3

  2. Execution, Runtime Structure, Memory Instances - https://www.w3.org/TR/wasm-core-2/exec/runtime.html#memory-instances