WebAssembly.Memory.prototype.grow()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The grow() protoype method of the Memory object increases the size of the memory instance by a specified number of WebAssembly pages.

Syntax

memory.grow(number);

Parameters

number
The number of WebAssembly pages you want to grow the memory by (each one is 64KiB in size).

Return value

The previous size of the memory, in units of WebAssembly pages.

Examples

The following example creates a new WebAssembly Memory instance with an initial size of 1 page (64KiB), and a maximum size of 10 pages (640KiB).

var memory = new WebAssembly.Memory({initial:1, maximum:10});

We can then grow the instance by one page like so:

const bytesPerPage = 64 * 1024;
console.log(memory.buffer.byteLength / bytesPerPage);  // "1"
console.log(memory.grow(1));                           // "1"
console.log(memory.buffer.byteLength / bytesPerPage);  // "2"

Note the return value of grow() here is the previous number of WebAssembly pages.

Specifications

Specification Status Comment
Web Assembly JavaScript API
The definition of 'grow()' in that specification.
Draft Initial draft definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 57 No support 52 (52)[1] No support (Yes) No support
Feature Chrome for Android Android Webview Edge Mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 57 57 No support 52.0 (52)[1] No support No support No support

[1] WebAssembly is enabled in Firefox 52+, although disabled in the Firefox 52 Extended Support Release (ESR.)

See also

Document Tags and Contributors

 Contributors to this page: lukewagner, chrisdavidmills, fscholz
 Last updated by: lukewagner,