Hacker News new | ask | show | jobs
by 11235813213455 2644 days ago
For sharing (byte) data, I think there is SharedArrayBuffer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

But else, yes, the sent and received data is serialized (when using ipc, else you can also send raw data through streams, and handle the serialization yourself)

3 comments

SharedArrayBuffer -> shared

ArrayBuffer -> ownership can be transferred around, but the data can only be owned by one thread at a time. The data itself isn't copied. Passing around ArrayBuffers back and forth is good enough for a lot of stuff. In a worker you can then put a node Buffer, TypedArray, or DataView around the ArrayBuffer again, if you want.

Supposedly SharedArrayBuffer and atomics have been in Node.js since version 9.

I wonder if there are any articles where people use them in threads.

memory sharing is explained in the article.