aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/javascript/reference/global_objects/webassembly/memory/grow/index.md
blob: e868d4621aee63d0fc23e8241e5b29724f162831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: WebAssembly.Memory.prototype.grow()
slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow
tags:
  - API
  - JavaScript
  - メソッド
  - Reference
  - WebAssembly
  - grow
  - memory
browser-compat: javascript.builtins.WebAssembly.Memory.grow
translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow
---
{{JSRef}}

**`grow()`** は [`Memory`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) オブジェクトのプロトタイプメソッドで、指定した WebAssembly ページの数だけメモリーインスタンスの大きさを拡張します。

## 構文

```js
grow(number)
```

## 引数

- _number_
  - : メモリーを拡大する WebAssembly ページ数 (それぞれは 64KiB の大きさ)。

### 返値

以前のメモリーの大きさを、 WebAssembly ページ単位で返します。

## 例

### grow の使用

以下の例では、新しい WebAssembly メモリーインスタンスを初期サイズ 1 ページ (64KiB)、最大サイズ 10 ページ (640KiB) で作成します。

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

それから、インスタンスを 1 ページ分拡張することができます。

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

なお、ここでの `grow()` の返値は直前の WebAssembly ページ数です。

## 仕様書

{{Specifications}}

## ブラウザーの互換性

{{Compat}}

## 関連情報

- [WebAssembly](/ja/docs/WebAssembly) 概要ページ
- [WebAssembly の概念](/ja/docs/WebAssembly/Concepts)
- [WebAssembly JavaScript API の使用](/ja/docs/WebAssembly/Using_the_JavaScript_API)