Detach buffers by sending to an empty message channel
This commit is contained in:
parent
e4693065fd
commit
15e71abdc5
@ -1,14 +1,22 @@
|
||||
/* eslint-disable camelcase */
|
||||
if (!window) var { MessageChannel } = require('worker' + '_threads')
|
||||
|
||||
function sodium_malloc (n) {
|
||||
return new Uint8Array(n)
|
||||
}
|
||||
|
||||
const sink = new MessageChannel()
|
||||
function sodium_free (n) {
|
||||
sodium_memzero(n)
|
||||
sink.port1.postMessage(n.buffer, [n.buffer])
|
||||
}
|
||||
|
||||
function sodium_memzero (arr) {
|
||||
arr.fill(0)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sodium_malloc,
|
||||
sodium_free,
|
||||
sodium_memzero
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user