JavaScript · Senior · Question 13 of 75

Why pass an ArrayBuffer to a worker as transferable: postMessage(buf, [buf])?

Explanation

Copying large data is expensive. A transfer hands over the memory instantly, and the sender's byteLength becomes 0. True shared memory is SharedArrayBuffer with Atomics, but it requires cross-origin isolation (COOP/COEP headers).

Further reading

Problem with a question

JavaScript · Senior · question 13

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz