Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道是否可以使用 N-API 让工作线程访问另一个工作线程创建的对象。虽然我不需要并发访问,但我目前通过序列化和反序列化来传输数据。但是,我的数据很大(JSON.stringify().length() 返回大约 50000000),所以我浪费了很多时间。我知道存在共享字节数组,但是将我的对象序列化成这些需要相同的时间。N-API 是否让我有可能让 thread2 访问 thread1 以低开销创建的对象?
仅当您的对象可以在没有 V8 的情况下访问时才有可能 - 即它不包含 V8 对象。二进制缓冲区,TypedArrays 工作。JS 数组,JS 对象没有。每个 worker_thread 在不同的 V8 隔离中运行,并且 V8 对象存储不是线程安全的,不能从其主线程外部访问。
TypedArray