通过这个(How expensive is RTTI?),很明显动态转换比静态类型比较昂贵得多,但我想知道是否值得在编译器选项(VS2010,/GR-)中关闭 RTTI 选项
我的代码中没有动态转换(我用静态转换替换了它们)。但是 (/GR-) 选项除了在使用动态转换时发出错误外还有其他作用吗?里面有内存或者代码优化吗?
提前致谢。
最佳答案
直from MSDN (强调我的):
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.
在您的情况下,关闭 RTTI 似乎是值得的。
关于c++ - 从编译器设置中关闭 RTTI 有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21400683/