简体   繁体   English

使用boost :: serialization大大增加了二进制大小

[英]Using boost::serialization greatly increases binary size

I use rather complex data structures (mostly using STL containers) in my app, and serialize them using Boost (v1.34). 我在应用程序中使用了相当复杂的数据结构(主要使用STL容器),并使用Boost(v1.34)对它们进行序列化。

Whenever I compile with debug symbols (gcc -g), the resulting executable gets huge - around 25 MB. 每当我使用调试符号(gcc -g)进行编译时,生成的可执行文件都会变得很大-大约25 MB。 Stripping all the debug symbols reduces the size to ~3 MB. 剥离所有调试符号会将大小减小到〜3 MB。

I tried to nail down the cause of the size increase, and it seems that serialization methods are the cause. 我试图确定导致大小增加的原因,并且看来序列化方法是原因。 Particularly, object files for modules that call serialization (code like "oarchive << myObject") are large, and commenting out the serialization part reduces the size significantly. 特别是,用于调用序列化的模块的目标文件(诸如“ oarchive << myObject”之类的代码)很大,注释掉序列化部分会大大减小大小。

Is it possible to prevent generation of these symbols, or to strip them selectively? 是否可以防止这些符号的产生或选择性地去除它们?
Stripping all the symbols is not an option, since I need debug symbols for my own code. 除去所有符号不是一个选择,因为我需要为自己的代码使用调试符号。

  1. Put your code with serialization calls to separate modules, compile them to large object files. 将带有序列化调用的代码放置到单独的模块中,然后将它们编译为大型目标文件。
  2. Use strip --strip-debug on them to remove only this big debugging symbols (which you will definitely need later to debug crashes inside serialization library :) 在它们上使用strip --strip-debug可以仅删除此较大的调试符号(以后肯定会需要使用它来调试序列化库中的崩溃:)
  3. Profit! 利润! Link stripped wrappers and unstripped other modules together. 将剥离的包装纸和未剥离的其他模块链接在一起。
strip -w -K '!*serialization*'

Easy, no need for compile time gymnastics. 简单,无需编译时进行体操。 Here's the improvement this made to my binary: 这是对我的二进制文件所做的改进:

# ls -lh EnrollGUI 
-rwxr-xr-x. 1 root root 17M Aug  8  2012 EnrollGUI*
# strip -w -K '!*serialization*' EnrollGUI
# ls -lh EnrollGUI 
-rwxr-xr-x. 1 root root 1.1M Aug  8  2012 EnrollGUI*

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM