Open saghul opened 1 month ago
There's likely some overlap with the resizable (Shared)ArrayBuffer proposal?
Hola! Not sure what that overlap would be, at a glance. Can you elaborate what you have in mind?
Your ask is for support of unmanaged buffers, right, where the embedder is responsible for allocating and releasing the buffer?
With resizable buffers, resizing also needs to be delegated to the embedder.
Oh I see now, thanks!
When creating a SAB using
JS_NewArrayBuffer
, thealloc_flag
is always set toFALSE
, which means we assume A SAB was previously allocated and we are just going to "dup" it.This doesn't work when all we want to is to maneuver a chunk of memory (I have this use case with FFI) since we didn't allocate the SAB in the first place.
I reckon we might want some
JS_NewSharedArrayBuffer
function to provide extra flexibility. In additionJSFreeArrayBufferDataFunc
doesn't apply for a SAB so we'd make it more specific.I worked this around on txiki.js by adding a magic number to the SAB header, this way I can detect if we allocated the SAB or if it's just external memory, but it's a hack at best.
Thoughts @chqrlie / @bnoordhuis ?