Moh*_*hti 6 c++ serialization deserialization julia
我有一个用C++编写的存储管理器,我想将一些对象从Julia传递给C++程序.对于我来说,接收内容作为一个字节数组就足够了,以后可以将其传递回Julia并轻松解码.
什么是最小化复制数据的最佳方法(并且还避免写入/读取磁盘)?
可以从C++程序中分配所需的内存并与Julia共享以序列化对象,或者从Julia获取指向已分配内存的指针到C++程序中.在后一种情况下,我不确定如何防止Julia方面的垃圾收集.另外,我不知道哪种序列化/反序列化方法更适合这种用例.
你能指导我找到Julia和C++之间这种轻量级序列化/反序列化的最佳方法吗?
编辑:如果答案是依赖于操作系统的,请给出Linux或macOS的答案.
不幸的是,我无法向您提供任何源代码,因为我没有使用过下面提到的任何 C++ 框架,也根本不了解 Julia。
The approach I've been following in a past project isn't as lightweight as sharing pointers to the memory already allocated by C++. However, since there hasn't been an answer yet, I just want to add my two cents on how I've been exchanging objects between programming languages (Java and C# in my case).
Instead of reading from and writing to the disc I've used a messaging queue to make both sub-systems exchange objects with each other.
Serialization, especially when it comes to more complex objects can be quite resource-hungry. However, I've come to like using protocol buffers for that matter as they serialize the pre-defined object into a stream of bytes.
An example for a C++ library for protocol buffers can be found in the Google Protobuffers. Respectively, a protocol buffer for Julia can be found in ProtoBuf.jl
The downside about using protocol buffers is that you need to have a defined message format which means that you already need to know what the objects you want to exchange look like beforehand.
A data exchange could be done using a messaging queue which instead of sharing pointers or writing to the disc uses the network interface of the local machine. A messaging queue I've been using already has been ZeroMQ as it is quite lightweight and fairly easy to use. Any other messaging queues should work for that purpose too though.
ZeroMQ 的 Julia 接口对于 C++ 分别是ZMQ.jl和cppzmq 。ZeroMQ 的完整指南对于您入门确实很有帮助,但您不需要完整的文档来实现您的目的。