Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new dictionary member to MemoryDescriptor #831

Closed
Zhang-Junzhi opened this issue Jul 6, 2018 · 2 comments
Closed

add a new dictionary member to MemoryDescriptor #831

Zhang-Junzhi opened this issue Jul 6, 2018 · 2 comments

Comments

@Zhang-Junzhi
Copy link

Zhang-Junzhi commented Jul 6, 2018

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.

@rossberg
Copy link
Member

rossberg commented Jul 6, 2018

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.

@Zhang-Junzhi
Copy link
Author

Thanks for the clarification.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants