WebAssembly.Memory.prototype.buffer - JavaScript 编辑
The buffer
prototype property of the WebAssembly.Memory
object returns the buffer contained in the memory.
Examples
Using buffer
The following example (see memory.html on GitHub, and view it live also) fetches and instantiates the loaded memory.wasm byte code using the WebAssembly.instantiateStreaming()
method, while importing the memory created in the line above. It then stores some values in that memory, then exports a function and uses it to sum some values.
WebAssembly.instantiateStreaming(fetch('memory.wasm'), { js: { mem: memory } })
.then(obj => {
var i32 = new Uint32Array(memory.buffer);
for (var i = 0; i < 10; i++) {
i32[i] = i;
}
var sum = obj.instance.exports.accumulate(0, 10);
console.log(sum);
});
Specifications
Specification |
---|
WebAssembly JavaScript Interface The definition of 'buffer' in that specification. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论