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
How to send SharedArrayBuffer from main process to Window processes #10409
Comments
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. To help make it easier for us to investigate your issue, please follow the contributing guidelines. |
Thanks for reaching out! Because we treat our issues list as the team's backlog, we close issues that are questions since they don't represent a task needing to be completed. For most questions about Electron there are a lot of options. Check out the Electron community. There are also a bunch of helpful people in this community forum that should be willing to point you in the right direction. |
Did you ever end up figuring this out? |
Hi, This may come in a bit late, but I did stumble upon this closed issue right here when doing researches on the exact same topic, so hopefully it could help other people looking for an answer. TL;DR: you can't use The MDN documentationSo, if we refer to the MDN documentation about
So to clarify this description:
Now, after checking a bit the ECMAScript specifications, I realize "cluster" and "agent" are terms coming from there, and I may not completely understand those concepts yet. But given this description on MDN and my different tests, the mapping I made to "process" and "thread" should be correct in this context. The ECMAScript specificationsNow if we look at the ECMAScript standard, first we see only a few mentions of threads, when describing execution Agents. Honestly, I didn't take the time to analyze that so I don't fully understand it. Now, about the mentions of OS processes (by looking for the word "process" and excluding all of the irrelevant occurrences):
And regarding mentions of The dedicated section about It's only when we reach the section about Memory Model that things could start getting interesting, but it's way too long to read right now, and the only thing I retain is: So we are back to the Agents section. Unfortunately, as of right now I can't really provide an exact interpretation of these specifications. How to share memory: using OS native APIsSo, nothing prevents you from writing a Node.js native addon (Node-API preferred) that would allocate and deallocate a block of shared memory. For instance on Windows: You can load that native addon on the main process side of Electron, and using node integration options in WebPreferences you can load that same native addon on the renderer process and its threads (Web Workers) as well, even though they advise against it. You would have several instances of your addon loaded, which is a duplication of data, but only for your addon state. The block of shared memory you would allocate, deallocate and pass around using your addon's exposed API would be the same and it would be shared memory. Now, I didn't mention the access part: reading and writing from that block of memory. You theoretically have two options, but you will see that there's a HUGE limitation with Electron which may bum you. Option 1: add custom APIs to read and write to the buffer. That's not standard, and only your code will know how to interact with it. Passing the buffer wrapper to 3rd-parties may not work unless they accept adapters. Option 2: wrap it in an
Your only hope if you want to go that route is either to have issue #35241 resolved or to build Electron yourself without that mentioned memory cage. References:
ConclusionIt's unfortunate that Electron resembles more and more to a black box webview, while it's probably the only viable option to build applications a bit more interesting than yet another TODO list or documentation websites wrappers. Of course, having The route towards using a native addon is more complex, and if you want compatibility with |
Regarding the custom build of Electron, I managed to make one, but there are cons:
Otherwise the idea is fairly simple:
The content of
Adapt the import depending on your needs. The important part here is the customization of the V8 options. With the generated build, I could use the solution I wrote in my previous comment and wrap my instances in |
I am working on an offline renderer for three.js for this project i need to share SharedArrayBuffer between main and window processes. I can create SharedArrayBuffer in main process and window processes but no way to share the reference to other processes, how can it be achieved?
OS : macOS Sierra 10.12.6 (16G29)
Electron : Built from master #cc666c7
The text was updated successfully, but these errors were encountered: