W3cubDocs

/JavaScript

WebAssembly.memory.grow

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
WebAssembly JavaScript Interface
The definition of 'grow()' in that specification.
Working Draft Initial draft definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 57 16 52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
No 44 11
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 57 57 Yes
Disabled
Yes
Disabled
Disabled This feature is behind the Experimental JavaScript Features preference.
52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
? 11 7.0
Server
Node.js
Basic support 8.0.0

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow