Web Workers 共享内存
在现代浏览器中,是否可以在多个网络工作者之间共享内存以进行读写(或至少只读)?如果没有,是否有计划实现此类功能?
我知道可以使用消息系统在工作人员之间传输数据,但这种方式有时不合适,例如由于大型数据结构的序列化开销。
Is it possible to share memory between several web workers for reading and writing(or at least for reading only) in the modern browsers? If not, are there plans to implement such feature?
I know that data may be transferred between workers by using message system, but such way sometimes is not suitable, for instance because of serialization overhead of large data structures.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有共享内存。根据定义,我们希望每个工作线程(“线程”)都有自己的生存空间。但是,目前您可以使用共享本地位置的 WebSQL,但这并不明智,因为它不是线程安全的。
将来我们可能能够使用indexedDB(当它被实现时!)
您可能想检查相反的方式并使用Shared Workers。这将使您能够从应用程序的多个选项卡/窗口中利用同一工作人员。我不确定它是否适合你的情况......
There is no shared memory. It's by definition that we wish each worker ('thread') will have its own arena to live in. However, currently you can use WebSQL are you shared local location BUT it's not wise since it's not thread safe.
In the future we might be able to use indexedDB (WHEN it will be implemented!)
You might want to check the other way around and use Shared Workers. This will give you the way to leverage the same worker from several tabs/windows of your app. I'm not sure if it will fit you case...