C++ serialize giude
2013-11-12 11:18
363 查看
A practical guide to C++ serialization
原网址:http://www.ocoudert.com/blog/2011/07/09/a-practical-guide-to-c-serialization/In a nutshell, serialization consists of writing data and objects on a support (a file, a buffer, a socket), so that they can be reconstructed later in the memory of the same or another computing host. The reconstruction process is also known as deserialization.
Serializing a primitive type like a bool, int, or float, is trivial: just write the data as it is (assuming that no compression is used). Serializing a pointer is different: the object it points to must be serialized first. That way deserializing the pointer
simply consists of setting its value to the memory address at which the object has been reconstructed.
We can distinguish three levels of complexity in serialization, depending on how complex the pointer (and reference) graph is:
The pointer graph is a forest (i.e., a set of trees). Data can simply be serialized bottom up with a depth first traversal of the trees.
The pointer graph is a directed acyclic graph (DAG), i.e., a graph without loop. We can still serialize the data bottom up, making sure we write and restore shared data only once.
The pointer graph is a general graph, i.e., it may have loops. We need to write and restore data with forward references so that loops are handled properly.
The text and XML archives are portable across 32 and 64 bits platforms.
Having a binary archive that is portable between 32 and 64 bits is not trivial, because C++ does not specify exactly the size of primitive types. For instance a long is usually 4 bytes on a 32 bits machine, and 8 bytes on a 64 bits machine. In practice though
it is pretty portable –there is a non-official version for a portable binary archive.
相关文章推荐
- leetcode_c++:树: Serialize and Deserialize Binary Tree(297)
- Protobuf C++ serialize到char*的方法
- (pbc lua 加入)c++_lua_Python with/without extension性能测试 (10万次SerializeToString & ParseFromString)
- 《The C++ programming language》读书笔记(2)——第二章:C++ 概览
- 使用标准C++的类型转换符:static_cast、dynamic_cast、reinterpret_cast、和const_cast。(转)
- C++使用心得
- C++ 对象是怎么死的?进程篇[转]
- c/c++ 处理整数的进制
- 深入探讨C++中的引用
- win7下用VS2010和Intel C++ 11编译Boost
- C++模板类的前置声明
- c/c++程序的内存分配
- 【C++】template template argument 模板参数模板
- C/C++中字符串与数字间转换方法
- C++strcmp用法
- Why C++ ? 王者归来
- C/C++开发语言系列之9---C++函数模板详解
- C++ 源码分析网址
- C++和Java动态数组比较
- 标准c++ 读写unicode文件