transferable object
An object, such as an ArrayBuffer, ImageBitmap or MessagePort, whose memory can be moved to another thread instead of copied.
In more detail
Listing it in postMessage's transfer list hands ownership over almost instantly, whatever its size. The sender's copy becomes detached and unusable, typically showing a length of zero.
Example
worker.postMessage(buffer, [buffer]); // buffer.byteLength is now 0 hereRelated terms
- postMessage() — The method used to send data between a page and a worker, or between windows, delivered as a message event on the other side.
- ArrayBuffer — A standard JavaScript object representing a block of raw binary memory, which you read and write through a typed array or DataView.
- ImageBitmap — A decoded image ready to draw on a canvas, which can be transferred to a worker without copying.
- MessagePort — One end of a two-way message channel created with MessageChannel, which can be transferred so two contexts talk directly.
- structured clone algorithm — The standard JavaScript algorithm for deep-copying values between threads and into storage, which handles Maps, Sets, Dates, typed arrays and circular references.
Taught in
- Web Workers: Off-Thread Computation And Structured Clone — Frontend Architecture & Web Platform