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

Creating WebAssembly Memory from existing ArrayBuffer #1226

Closed
briantbutton opened this issue Aug 7, 2018 · 4 comments
Closed

Creating WebAssembly Memory from existing ArrayBuffer #1226

briantbutton opened this issue Aug 7, 2018 · 4 comments

Comments

@briantbutton
Copy link

Is there a way to do this?

Starting from the beginning:
I create a complicated structure, optimized for fast display in an ArrayBuffer. Roughly 100Mbytes. User input causes the code to do computations against the structure and present results on WebGL. Because the structure is so optimized - and I use WebAssembly - I can get good response times.
However, the process for building the structure takes a while and is about to take much longer. I would like to delegate the "structure creation" code to a Web Worker. The user can then do things while the structure is being built. When it is complete, the ArrayBuffer is passed to the main thread and the user can do even more things. Yay!!
But I don't know how to put the existing ArrayBuffer into a WebAssembly.Memory in the main thread. I can do a copy in Javascript but I seriously dislike that option.
Lil help please!

@jfbastien
Copy link
Member

You want to create the WebAssembly.Memory, get its buffer as an ArrayBuffer, and deal with that. The reason is that WebAssembly memories often use over-allocation to generate better WebAssembly code, which regular ArrayBuffer doesn't do. The design doesn't allow creating WebAssembly.Memory from ArrayBuffer on purpose 😄

@briantbutton
Copy link
Author

I will note that I read issue #1162 and was left feeling confused and pessimistic.

FWIW: To use WebAssembly today with only one Memory, I wrote elaborate WebAssembly code with pages, directories, address ranges, etc. . . . basically application-specific memory management. There are logically six tables inside one array. One can do a lot with one Memory if you are sufficiently motivated.

@briantbutton
Copy link
Author

jfbastien, OK. Thanks for the quick response.

@binji
Copy link
Member

binji commented Aug 8, 2018

See also WebAssembly/spec#831.

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