Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "external" buffers when creating a SharedArrayBuffer #471

Open
saghul opened this issue Jul 16, 2024 · 5 comments
Open

Support "external" buffers when creating a SharedArrayBuffer #471

saghul opened this issue Jul 16, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@saghul
Copy link
Contributor

saghul commented Jul 16, 2024

When creating a SAB using JS_NewArrayBuffer, the alloc_flag is always set to FALSE, 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 addition JSFreeArrayBufferDataFunc 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 ?

@saghul saghul added the enhancement New feature or request label Jul 16, 2024
@bnoordhuis
Copy link
Contributor

There's likely some overlap with the resizable (Shared)ArrayBuffer proposal?

@saghul
Copy link
Contributor Author

saghul commented Jul 30, 2024

Hola! Not sure what that overlap would be, at a glance. Can you elaborate what you have in mind?

@bnoordhuis
Copy link
Contributor

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.

@saghul
Copy link
Contributor Author

saghul commented Jul 30, 2024

Oh I see now, thanks!

@saghul
Copy link
Contributor Author

saghul commented Sep 10, 2024

Nevermind, turns out some of the ffi code in txiki.js was using a SAB by mistake. A simple AB is enough with a NULL dealloc function.

I'll revisit if need be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants