问题描述
由此(RTTI 有多贵?),似乎很明显动态转换是比静态类型比较昂贵得多,但我想知道在编译器选项(VS2010,/GR-)中关闭 RTTI 选项是否值得
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-)
我的代码中没有动态转换(我用静态转换替换了它们).但是 (/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?
提前致谢.
推荐答案
Straight 来自MSDN(强调我的):
Straight from MSDN (emphasis mine):
当/GR 打开时,编译器定义 _CPPRTTI 预处理器宏.默认情况下,/GR 处于打开状态./GR- 禁用运行时类型信息.
如果编译器无法静态解析代码中的对象类型,请使用/GR.当您的代码使用 dynamic_cast Operator 或 typeid 时,您通常需要/GR 选项.但是,/GR 会增加图像的 .rdata 部分的大小.如果您的代码不使用 dynamic_cast 或 typeid,则/GR- 可能会生成较小的图像.
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.
在您的情况下,关闭 RTTI 似乎是值得的.
Looks like turning RTTI off is worth it in your case.
这篇关于从编译器设置中关闭 RTTI 有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!