简体   繁体   English

如何在本机节点模块中维护零拷贝?

[英]How can I maintain zero-copy in a native node module?

I'm writing a native node module for an in-process database which features zero-copy data lookups. 我正在为进程内数据库编写一个本机节点模块,该数据库具有零拷贝数据查找功能。 I'd like my module to also have this ability. 我希望我的模块也具备这种能力。 In other words, when I get data from the database, I'd like to pass the data to V8 without the need to copy memory or the need to parse something. 换句话说,当我从数据库中获取数据时,我想将数据传递给V8,而无需复制内存或需要解析某些内容。

How can I do this? 我怎样才能做到这一点?

So far, all the ways I have seen involved either parsing back and forth between JSON (pretty much a waste of resources in this case) or instantiating V8 data structures and copying data into them. 到目前为止,我所看到的所有方法都涉及在JSON之间来回解析(在这种情况下几乎浪费资源)或实例化V8数据结构并将数据复制到它们中。

NOTE: in case you are wondering, zero-copy data lookup means (in a nutshell) that the database engine does not need to copy memory when it retrieves data. 注意:如果您想知道,零拷贝数据查找意味着(简而言之)数据库引擎在检索数据时不需要复制内存。

I think I found the solution, although it is rather limited. 我想我找到了解决方案,虽然它相当有限。

Interesting documentation can be found here: https://developers.google.com/v8/ (overview) and http://izs.me/v8-docs/main.html (API docs) 有趣的文档可以在这里找到: https//developers.google.com/v8/ (overview)和http://izs.me/v8-docs/main.html(API docs)

Seems that V8 has an ExternalStringResource class which can be used for this purpose: 似乎V8有一个ExternalStringResource类,可用于此目的:
http://izs.me/v8-docs/classv8_1_1String_1_1ExternalStringResource.html http://izs.me/v8-docs/classv8_1_1String_1_1ExternalStringResource.html

Node itself also has a Buffer class which can also be used for similar ends: Node本身也有一个Buffer类,它也可以用于类似的目的:
http://nodejs.org/api/buffer.html http://nodejs.org/api/buffer.html

By using the above two classes, it is possible to implement zero-copy in a native node module for strings and byte arrays. 通过使用上述两个类,可以在本机节点模块中为字符串和字节数组实现零拷贝。 Unfortunately it seems that (at the time I'm writing this) it isn't possible for objects. 不幸的是,似乎(在我写这篇文章的时候)对象是不可能的。

EDIT 编辑

In case you are okay with just having the zero-copy ability for the string or Buffer properties of the object (but not the whole object itself), it can easily be implemented using the interceptors or accessors in the V8 API. 如果您只对对象的stringBuffer属性(但不是整个对象本身)具有零复制能力,则可以使用V8 API中的拦截器或访问器轻松实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在 C++ 中从 const char * 数组进行零拷贝 std::string 分配吗? - Can I do a zero-copy std::string allocation in C++ from a const char * array? CUDA零拷贝性能 - Cuda zero-copy performance 如何实现零拷贝形式的gRPC C++ - How to implement zero-copy form gRPC c++ Eigen SparseMatrix的零拷贝构造 - Zero-copy construction of an Eigen SparseMatrix 如何在C ++中使用无锁循环缓冲区实现零拷贝tcp - How to implement zero-copy tcp using lock-free circular buffer in C++ 如何从 pybind11 中的 c++ 原始指针获取零拷贝视图? - How to get a zero-copy view from c++ raw pointer in pybind11? Android上的零拷贝摄像头处理和渲染管道 - Zero-copy Camera Processing and Rendering Pipeline on Android 谷物和 Boost Serialization 是否使用零拷贝? - Do cereal and Boost Serialization use zero-copy? 如何在本机Node.js模块中将事件处理程序附加到流程的出口? - How can I attach an event handler to the process's exit in a native Node.js module? 通过ZeroMQ接收对象作为字符串然后通过另一个套接字以零拷贝发送的正确方法是什么? - What is the correct way to receive an object as a string through ZeroMQ and then send it with zero-copy through another socket?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM