yanni's answer shows how to send (transfer ownership) one buffer to a web worker: Using transferable objects from a Web Worker
How would I send multiple buffers (in an array) to a web worker (without copying)?
yanni's answer shows how to send (transfer ownership) one buffer to a web worker: Using transferable objects from a Web Worker
How would I send multiple buffers (in an array) to a web worker (without copying)?
This has been answered elsewhere, but google brought me here first before I eventually found the answer here.
You can pass multiple buffers to a web worker without performing a copy using Transferable objects:
The worker case, the first argument is the data and the second is the list of items that should be transferred. The first argument doesn't have to be an ArrayBuffer by the way. For example, it can be a JSON object:
worker.postMessage(
{data: int8View, moreData: anotherBuffer},
[int8View.buffer, anotherBuffer]
);
Worker#postMessage
takes an array of transferable objects,
var worker = new Worker("...");
var buffers = [new ArrayBuffer, new ArrayBuffer, new ArrayBuffer];
var message = {buffers: buffers};
worker.postMessage(message, buffers);
Here's an example fiddle, http://jsfiddle.net/g247v/