You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, people want to pass a ready-made ArrayBuffer to a WebAssembly module without copying, this seems impossible in wasm for now. We can add a new dictionary member bufferToTransfer to MemoryDescriptor to make it possible.
Upon calling WebAssembly.Memory, the data becomes neutered, and the inherent address of imageData.data directly becomes the memory address, if the length of the original data is bigger than initial, they get truncated.
This way, developers don't have to copy the data after creating the memory.
The text was updated successfully, but these errors were encountered:
Engines use special implementation techniques for memories, e.g. to implement zero-cost bounds checks. So they must be allocated in a special way, at specific addresses, and with specific sizes in an implementation. For that reason, it is not possible to allow adopting an arbitrary ArrayBuffer as a memory.
BTW, I am wondering things can work the other way around. I'll file a issue in offscreenCanvas for allowing outputing the image data in an existing ArrayBuffer.
Sometimes, people want to pass a ready-made ArrayBuffer to a WebAssembly module without copying, this seems impossible in wasm for now. We can add a new dictionary member
bufferToTransfer
to MemoryDescriptor to make it possible.For example, let's see the following pesudo code:
offscreenCanvas.drawImage(...);
imageData = offscreenCanvas.getImageData();
WebAssembly.Memory({initial: 1, maximum: 2, bufferToTransfer: imageData.data});
Upon calling WebAssembly.Memory, the data becomes neutered, and the inherent address of imageData.data directly becomes the memory address, if the length of the original data is bigger than
initial
, they get truncated.This way, developers don't have to copy the data after creating the memory.
The text was updated successfully, but these errors were encountered: