aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/global_objects/webassembly/memory/index.html
blob: edb189e2ae89ff4f6d82e167307ae32108439d06 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
title: WebAssembly.Memory()
slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory
translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory
---
<div>{{JSRef}}</div>

<p><code><strong>WebAssembly.Memory()</strong></code> 생성자는 WebAssembly <code>Instance</code>가 액세스하는 메모리의 원시 바이트를 가진 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a>(크기조정이 가능)인 새 <code>Memory</code> 객체를 만듭니다.</p>

<p>메모리는 자바스크립트 혹은 WebAssembly 코드 안에서 만들어지며 자바스크립트 그리고 WebAssembly에서 접근하거나 변경이 가능합니다.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">var myMemory = new WebAssembly.Memory(memoryDescriptor);</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><em>memoryDescriptor</em></dt>
 <dd>다음의 멤버를 가질수 있는 객체입니다.
 <dl>
  <dt><em>initial</em></dt>
  <dd>WebAssembly Page의 단위별 WebAssembly 메모리의 초기 크기입니다.</dd>
  <dt><em>maximum {{optional_inline}}</em></dt>
  <dd>WebAssembly 메모리의 최대 크기는 WebAssembly 페이지 단위로 증가 할 수 있습니다. 이 매개 변수가 있으면 <code>maximum</code> 매개 변수는 엔진에 대해 메모리를 전면에 예약하도록 합니다. 그러나 엔진은 이 예약 요청을 무시하거나 클램핑 할 수 있습니다. 일반적으로 대부분의 WebAssembly 모듈은 <code>maximum</code> 값을 설정할 필요가 없습니다.</dd>
 </dl>
 </dd>
</dl>

<div class="note">
<p><strong>Note</strong>: WebAssembly 페이지의 크기는 65,536 바이트로 64KiB로 고정되어 있습니다.</p>
</div>

<h3 id="Exceptions">Exceptions</h3>

<ul>
 <li><code>memoryDescriptor</code>가 object 유형이 아닌 경우 {{jsxref ( "TypeError")}}가 발생합니다.</li>
 <li><code>maximum</code>이 지정되고 <code>initial</code>보다 작은 경우 {{jsxref ( "RangeError")}}가 발생합니다.</li>
</ul>

<h2 id="Memory_instances"><code>Memory</code> instances</h2>

<p>모든 <code>Memory</code> 인스턴스는 <code>Memory()</code>생성자의 <a href="/ko/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/prototype">prototype object</a>를 상속합니다.이 인스턴스는 모든 <code>Memory</code> 인스턴스에 적용되도록 수정할 수 있습니다.</p>

<h3 id="Instance_properties">Instance properties</h3>

<dl>
 <dt><code>Memory.prototype.constructor</code></dt>
 <dd>이 객체의 인스턴스를 생성 한 함수를 돌려줍니다. 기본적으로 이것은 {{jsxref("WebAssembly.Memory()")}} 생성자입니다.</dd>
 <dt>{{jsxref("WebAssembly/Memory/buffer","Memory.prototype.buffer")}}</dt>
 <dd>메모리에 포함 된 버퍼를 반환하는 접근 자 속성입니다.</dd>
</dl>

<h3 id="Instance_methods">Instance methods</h3>

<dl>
 <dt>{{jsxref("WebAssembly/Memory/grow","Memory.prototype.grow()")}}</dt>
 <dd>지정된 수의 WebAssembly 페이지 (각각 64KB 크기)만큼 메모리 인스턴스의 크기를 늘립니다.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<p><code>WebAssembly.Memory</code> 객체를 가져 오는 두 가지 방법이 있습니다. 첫 번째 방법은 JavaScript에서 생성하는 것입니다. 다음 예제에서는 초기 크기가 10 페이지 (640KiB)이고 최대 크기가 100 페이지 (6.4MiB) 인 새 WebAssembly 메모리 인스턴스를 만듭니다.</p>

<pre class="brush: js">var memory = new WebAssembly.Memory({initial:10, maximum:100});</pre>

<p><code>WebAssembly.Memory</code> 객체를 가져 오는 두 번째 방법은 WebAssembly 모듈에서 내보냅니다. 다음 예제는 (GitHub의 <a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/memory.html">memory.html</a>을 보세요. <a href="https://mdn.github.io/webassembly-examples/js-api-examples/memory.html">라이브로 보기</a>) 생성된 메모리를 가져 오는 동안 {{jsxref("WebAssembly.instantiateStreaming()")}} 메소드를 사용하여로드 된 memory.wasm 바이트 코드를 가져 와서 인스턴스화합니다. 위의 줄에. 그런 다음 메모리에 일부 값을 저장 한 다음 함수를 내 보낸 다음 일부 값의 합계에 사용합니다.</p>

<pre class="brush: js">WebAssembly.instantiateStreaming(fetch('memory.wasm'), { js: { mem: memory } })
.then(obj =&gt; {
  var i32 = new Uint32Array(memory.buffer);
  for (var i = 0; i &lt; 10; i++) {
    i32[i] = i;
  }
  var sum = obj.instance.exports.accumulate(0, 10);
  console.log(sum);
});</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('WebAssembly JS', '#webassemblymemory-objects', 'Memory')}}</td>
   <td>{{Spec2('WebAssembly JS')}}</td>
   <td>Initial draft definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>


<p>{{Compat("javascript.builtins.WebAssembly.Memory")}}</p>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/WebAssembly">WebAssembly</a> overview page</li>
 <li><a href="/en-US/docs/WebAssembly/Concepts">WebAssembly concepts</a></li>
 <li><a href="/en-US/docs/WebAssembly/Using_the_JavaScript_API">Using the WebAssembly JavaScript API</a></li>
</ul>