c++ - 从编译器设置中关闭 RTTI 有什么好处?

标签 c++ visual-c++ rtti dynamic-cast static-cast

通过这个(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/

相关文章:

c++ - 在 C++11 基于范围的 'for' 循环中获取对 STL 容器元素的引用

c++ - 在 C++ 中用正斜杠或双反斜杠替换反斜杠

c++ - VC++目录表现奇怪

c++ - 虚拟接口(interface) Dtor && Dynamic_Cast

C++ 将基指针转换为接口(interface)指针

c++ - 在定义之前显式实例化模板函数

C++ 泛型数组实现

C++ 在非成员函数中无效使用 'this'

c++ - 在 C++ 中,是否允许对象在其生命周期内合法地更改其类型?

c++ - 如何将整个 Visual c++ 项目加载到 Enterprise Architect 中以对其进行逆向工程?