Thank you for the explanation! So I will have to copy the data from js into the Wasm module's memory, call the Wasm function to operate on the data, and then finally copy it back to javascript. In this case I wonder if using Wasm over js will yield in any performance improvements, so I will test it out.
It seems it could be worth doing this since this is what they are doing here in the WebAssembly Video Editor, but I'm getting much lower framerate for Wasm compared to js in both Chrome and Firefox: https://github.com/shamadee/web-dsp https://d2jta7o2zej4pf.cloudfront.net/ On Tue, Oct 24, 2017 at 2:01 PM, Jukka Jylänki <[email protected]> wrote: > It is not possible to pass ArrayBuffers or ArrayBufferViews from > JavaScript to WebAssembly. WebAssembly operates only on a single > linear heap that is bound as its own memory space, so it's only > possible to pass pointers (indices) to that one memory buffer. So > currently you would have Wasm operate on its own memory, and then > going out to JS, copy the data from the singleton Wasm memory out to > other JavaScript ArrayBuffers. > > There have been talks about expanding Wasm to be able to operate on > multiple ArrayBuffers at a time, by expanding the opcode list to allow > specifying one of multiple ArrayBuffers which to manipulate, but > currently that kind of feature does not yet exist. > > 2017-10-23 15:11 GMT+03:00 Andrew Varga <[email protected]>: > > This actually looks very helpful, but I wonder if there is a "cleaner > > looking" way to actually "pass" an arraybuffer from js to a wasm module: > > https://stackoverflow.com/questions/46861475/how-can-i- > find-out-the-address-of-a-webassembly-buffer-and-return-it-to-javascri > > > > On Sun, Oct 22, 2017 at 4:35 PM, Andrew Varga <[email protected]> > wrote: > >> > >> Hi, > >> > >> I'm having a hard time achieving something that sounds easy: > >> - create an ArrayBufferView instance in JavaScript eg.: new > >> Uint8Array([1,2,3] > >> - pass this to a function in a wasm module that will operate on it and > >> change some of the values (it will not create a new array) > >> - be able to access the modified array in JavaScript > >> > >> I'm trying to achieve this with as little glue-code as possible, my > setup > >> is here: > >> https://github.com/andrewvarga/wasm_test > >> > >> When I run index.html, the console output is 29 which I believe comes > from > >> 23 + 6 (see buffertest.c), so I must be doing something very wrong. > >> > >> What I'm looking for is the simplest, smallest, fastest way to allow > wasm > >> module to change an array (like adding 6 to each element that I tried > to do > >> here). > >> > >> Any help would be very much appreciated! > >> > >> Thank you, > >> Andrew > >> > >> > >> -- > >> You received this message because you are subscribed to a topic in the > >> Google Groups "emscripten-discuss" group. > >> To unsubscribe from this topic, visit > >> https://groups.google.com/d/topic/emscripten-discuss/ > ecAgoEwK2ME/unsubscribe. > >> To unsubscribe from this group and all its topics, send an email to > >> [email protected]. > >> For more options, visit https://groups.google.com/d/optout. > > > > > > -- > > You received this message because you are subscribed to the Google Groups > > "emscripten-discuss" group. > > To unsubscribe from this group and stop receiving emails from it, send an > > email to [email protected]. > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "emscripten-discuss" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/emscripten-discuss/ecAgoEwK2ME/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
