Can I disable RTTI selectively in my code base to reduce the binary size?

淺唱寂寞╮ 提交于 2021-02-10 07:43:45

问题


I'm working on an iPhone app that uses C++ and is almost at the 100 MB mark (the point at which Apple won't let people download it via WWAN). I've taken many steps to reduce the binary size, such as removing unneeded third-party dependencies. However, the app, and in particular the binary, is still large because it has a lot of features.

I've heard that disabling RTTI can reduce the binary size. Would it be possible to turn off RTTI for some files, e.g. all files without the strings "typeid" or "dynamic_cast" in them?


回答1:


The space cost of RTTI is not associated with using it (via typeid or dynamic_cast), but of the type information associated with each class. Thus the benefit would be to disable RTTI for individual classes (or groups of classes).

I know no such way to do that.

You might find that if you can reduce the number of classes with virtual functions, you can reduce the amount of RTTI information. (For example, not all base classes need to have a virtual destructor - you only need that if you might call delete pBase.)

The other thing that can blow up executable size, is lots of templates. In many cases you can make template functions which just forward to non-template functions to do the real work.



来源:https://stackoverflow.com/questions/46102982/can-i-disable-rtti-selectively-in-my-code-base-to-reduce-the-binary-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!