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
Using grow
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 |
---|
WebAssembly JavaScript Interface The definition of 'grow()' in that specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
grow | Chrome Full support 57 | Edge Full support 16 | Firefox
Full support
52
| IE No support No | Opera Full support 44 | Safari Full support 11 | WebView Android Full support 57 | Chrome Android Full support 57 | Firefox Android
Full support
52
| Opera Android Full support 43 | Safari iOS Full support 11 | Samsung Internet Android Full support 7.0 | nodejs Full support 8.0.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.