What's the advantages of turning off RTTI from compiler setting?

有些话、适合烂在心里 提交于 2019-12-23 19:15:32

问题


By this(How expensive is RTTI?), it seems clear that dynamic casting is much expensive than static type comparison, but I wonder if it would be worth to turn off RTTI option in compiler option(VS2010, /GR-)

I have no dynamic cast in my code(I replaced them with static cast). But does (/GR-) option do any other than emitting errors when using dynamic cast? Is there any memory or code optimization in there?

Thanks in advance.


回答1:


Straight from MSDN (emphasis mine):

When /GR is on, the compiler defines the _CPPRTTI preprocessor macro. By default, /GR is on. /GR- disables run-time type information.

Use /GR if the compiler cannot statically resolve an object type in your code. You usually need the /GR option when your code uses dynamic_cast Operator or typeid. However, /GR increases the size of the .rdata sections of your image. If your code does not use dynamic_cast or typeid, /GR- may produce a smaller image.

Looks like turning RTTI off is worth it in your case.




回答2:


There may be some memory decrease (since the data required for RTTI are not needed), but in most practical cases you will find it completely negligible, so in most practical cases it is not worth it.



来源:https://stackoverflow.com/questions/21400683/whats-the-advantages-of-turning-off-rtti-from-compiler-setting

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