3 ms·
If you use Web Workers, you are going to have to use message passing. There is no other way to communicate with a Worker. There are no truly shared objects betw
by satori99 12y ago
If you use Web Workers, you are going to have to use message passing. There is no other way to communicate with a Worker. There are no truly shared objects between js threads.
However, it is still possible to post binary data to a worker and back again without making a copy of it, by using Transferable Objects [1].
You simply have to provide an array of the arraybuffers to move as the second paramter to postMessage(). The caveat is that the data is no longer available to the posting thread after the postMessage call (TypedArray length will be zero).
[1] http://updates.html5rocks.com/2011/12/Transferable-Objects-Lightning-Fast http://updates.html5rocks.com/2011/12/Transferable-Objects-L...
- leeoniya 12y agoi'm aware of transferable objects, but it really defeats the purpose of parallelizing analysis of the same thing if that thing becomes unavailable to read after transfer. it would be great to just tell a worker to read a specific bounding box from an existing canvas without having to give up the canvas entirely or copying the bounding box contents into it.
- satori99 12y agoYeah, that would be awesome. Probably not going to happen with actual DOM objects anytime soon.