使用IndexedDB的隔离之间的共享内存

使用IndexedDB的隔离之间的共享内存

本文介绍了使用IndexedDB的隔离之间的共享内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用Isolates,想知道如果使用IndexedDB在分离之间共享数据是一个很好的沟通方式?具体来说,我想要一个Isolate能够写它,然后告诉其他Isolates他们可能readonly它。这是一旦被写入并且相当大,将被认为是不变的数据。我想这样做的主要原因是因为我不想发送一个6MB的地图到3个不同的隔离,因为它是一个有点密集的程序。

I'm working with Isolates right now and wanted to know if using IndexedDB to share data between Isolates is a good way to communicate? Specifically, I want one Isolate to be able to write to it, then tell the other Isolates they may readonly it. This is data that would be considered unchanging once it is written and is fairly large. The main reason I want to do this is because I don't want to send a 6MB Map to 3 different Isolates since it is a bit intensive on the program.

推荐答案

Web worker允许你在不复制的情况下在工作线程之间传递数组缓冲区。但是,一旦你将数组缓冲区传递给另一个工作者,原来的工作者就无法访问它的内容了。

Web workers allow you to pass array buffers between workers without copying. However once you pass an array buffer to another worker the original worker looses access to its contents.

所以你可以尝试将数据结构存储在数组缓冲区中,

So you could try store your data structure in an array buffer to take advantage of this.

查看此和 。

因此,对于Dart,将您的数据存储在,然后通过dartjs编译时,不应该复制,而是传输。

So for Dart, store your data in a ByteData, and then when compiled via dartjs this should not be copied, but transferred.

注意:Mozilla是也做了一些实验与跨多个Web工作者的数组缓冲区的共享可变访问。这是为了允许emscripten将多线程c代码编译为javascript。这种共享访问可能需要一段时间才能实现标准化和广泛实施。

Side note: Mozilla is also doing some experimentation with shared mutable access to array buffers across multiple web workers. This is to allow emscripten to compile multithreaded c code to javascript. This sort of shared access will likely take a while to get standardised and widely implemented.

这篇关于使用IndexedDB的隔离之间的共享内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:02