C++ Serialization Performance(C++ 序列化性能)
问题描述
我正在构建一个分布式 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++ 序列化性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 序列化性能
基础教程推荐
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01