我正在构建一个分布式 C++ 应用程序,它需要对在不同进程和计算机之间传递的简单数据结构进行大量序列化和反序列化.
I'm building a distributed C++ application that needs to do lots of serialization and deserialization of simple data structures that's being passed between different processes and computers.
我对序列化复杂的类层次结构不感兴趣,但更多的是发送具有一些简单成员(如数字、字符串和数据向量)的结构.数据向量通常可以有好几兆字节大.我担心基于 text/xml 的方法太慢了,我真的不想自己写这个,因为字符串编码和数字字节序等问题可能会使它比表面看起来更复杂.
I'm not interested in serializing complex class hierarchies, but more of sending structures with a few simple members such as number, strings and data vectors. The data vectors can often be many megabytes large. I'm worried that text/xml-based ways of doing it is too slow and I really don't want to write this myself since problems like string encoding and number endianess can make it way more complicated than it looks on the surface.
我一直在研究协议缓冲区和 boost.serialize.根据文档协议缓冲区似乎非常关心性能.Boost 似乎更轻量级,因为您没有用于指定数据格式的外部语言,我觉得这对于这个特定项目非常方便.
I've been looking a bit at protocol buffers and boost.serialize. According to the documents protocol buffers seems to care much about performance. Boost seems somewhat more lightweight in the sense that you don't have an external language for specifying the data format which I find quite convenient for this particular project.
所以我的问题归结为:有谁知道对于我上面描述的典型用例,boost 序列化是否很快?
So my question comes down to this: does anyone know if the boost serialization is fast for the typical use case I described above?
此外,如果还有其他适合此用途的库,我很乐意听到.
Also if there are other libraries that might be right for this, I'd be happy to hear about them.
我强烈建议使用协议缓冲区.它们使用起来非常简单,提供出色的性能,并处理字节顺序和向后兼容性等问题.为了使其更具吸引力,序列化数据与语言无关,这要归功于众多语言实现.
I would strongly suggest protocol buffers. They're incredibly simple to use, offer great performance, and take care of issues like endianness and backwards compatibility. To make it even more attractive, serialized data is language-independent thanks to numerous language implementations.
这篇关于C++ 序列化性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!