- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
今天有个同事来问我标题中提到的问题。
他目前正在尝试减少代码库的二进制占用空间,该代码库也用于小型目标(如 Cortex M3 等)。显然他们已经决定在打开 RTTI 的情况下进行编译(实际上是 GCC),以支持正确的异常处理。
嗯,他的主要提示是为什么 std::type_info::name()
实际上完全需要支持 RTTI,并问我是否知道一种方法来抑制生成支持这一点所需的字符串文字,或者至少缩短它们。
std::type_info::name
const char* name() const;
Returns an implementation defined null-terminated character string containing the name of the type. No guarantees are given, in particular, the returned string can be identical for several types and change between invocations of the same program.
A ,- 但是编译器特定的-,例如的实现dynamic_cast<>
运算符(operator)不会使用此信息,而是使用类似于哈希标签的东西来确定类型(类似于 catch()
具有异常处理的 block )。
我认为后者在当前的标准定义中明确表达了
我不得不同意,我也没有真正看到使用 std::type_info::name()
的意义。 ,而不是用于调试(记录)目的。我不是 100% 确定在当前版本的 GCC(我认为他们使用的是 4.9.1)的情况下,仅在没有 RTTI 的情况下异常处理也能正常工作,所以我犹豫是否建议直接关闭 RTTI。dynamic_casts<>
也是这种情况。在他们的代码库中使用,但对于这些,我只是建议不要使用它,支持 static_cast
(它们实际上没有插件之类的东西,或者除了断言之外不需要运行时类型检测)。
std::type_info::name()
的实际生产代码级用例?除了日志记录?有没有人知道如何克服(解决)这些无用字符串文字的生成(假设它们永远不会被使用)?
真的(仍然)需要 RTTI 来支持 GCC 的异常处理吗?
(这部分现在由 @Sehe's answer 很好地解决了,我已经接受了。对于代码中使用的任何异常,剩余生成的 std::type_info
实例仍然存在另一个子问题。我们很确定,这些文字永远不会在任何地方使用)
相关位: Strip unused runtime functions which bloat executable (GCC)
最佳答案
隔离这个位:
answer是的:
-fno-rtti
Disable generation of information about every class with virtual functions for use by the C++ runtime type identification features (
dynamic_cast
andtypeid
). If you don't use those parts of the language, you can save some space by using this flag. Note that exception handling uses the same information, but it will generate it as needed. Thedynamic_cast
operator can still be used for casts that do not require runtime type information, i.e. casts tovoid *
or to unambiguous base classes.
关于c++ - std::type_info::name() 的实际目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28861760/
我有两个维度 DimFlag 和 DimPNL 以及一个事实表 FactAmount 。我正在寻找:当 pnl 是 stat(Is Stat=1) 时:sum (Actual x FlagId)对于
我想对包含其部分内容的文本字段执行简单搜索,但我不知道从哪里开始。我基本上想要人们对“包含搜索”的期望。如果我在 issue 中搜索 345 ,我会想要这个结果: 123456 234567 3456
我在 VBE 的 C# 插件中有这段代码(强调“VBE”:它不是 MS-Office 插件): public abstract class HostApplicationBase : IHostApp
我有一个 ImageView,它显示来自资源的图像。ImageView 的宽度是固定的 (60dp)。高度设置为 wrap_content。调整图像大小以适合此宽度(节省宽高比 - 这很完美) 问题是
我正在建立一个网站,但遇到了一个问题:谷歌浏览器开发者工具中的背景以较低/较高的分辨率延伸。当我直接从手机打开网站时,背景不适合屏幕,只是“剪切”了背景。 这是网站:https://feargames
好吧,首先,这是 HTML 模板: ... ... ... ... 如您所见,页面位于标题下方,并且通过 JS 代码可见
我读到了 BK-trees (Burkhard-Keller-Trees) 几个月前,据说这是一种保存您想通过距离度量再次读取的内容的好方法。因此,在每种情况下,您都希望通过相似性检索某些内容。 然而
在 python 中,很容易根据字符数用空格填充字符串。例如: print "aaa".ljust(10) + "end" print "www".ljust(10) + "end" 输出是: aaa
我的问题不是特定于编程语言的,而是更通用的问题,以了解人们的思维方式。 通常在大型开发公司中,每项工作都有特定的角色,例如程序员和架构师。因此架构师的观点是拥有完美的架构师和解决方案设计,另一方面程序
我想将数据传递给 then 方法,但是当我通过给它 this.passedResolve 来执行此操作时,它会得到 undefined function Promises(callback){
我希望使用 Erlang/Elixir 在金融市场创建一个平台即服务。我将在金融市场提供 AWS lambda 风格的函数,但我计划向客户分发我自己的基于 ARM 的硬件终端(基于 Nvidia Je
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我已经看到很多代码,这些代码使用Runnable的循环时间来实现某些计时器/超时。问题是,如果有人决定更改此Runnable的循环时间,则计时器将不正确。 例: #define FOO_TIMER_1
当我将 WPF DataGrid 的 ColumnHeaderHeight 设置为 Auto (double.NaN) 时,如何获取列标题的实际呈现高度? 我似乎无法在 DataGrid 类中找到该属
目前最实用的png修复方法是什么?轻量级,支持背景重复和背景位置。 最佳答案 IE7.JS在我看来: IE7.js is a JavaScript library to make Microsoft
我已经进行了长时间的搜索并尝试了常见的嫌疑人,但现在是寻求帮助的时候了。 我的 Android Activity 非常愉快地从 SQLite 加载 EditText、Spinner 和 CheckBo
因此,我在 MySQL 全文中创建精确搜索时遇到了一些困难。 在我的数据库中,我正在尝试查找标题中包含特定关键字的职位。 所以我可以尝试 WHERE MATCH(jobTitle) AGAINST (
我正在尝试将 JavaScript 包含到一个表单应用程序中,该应用程序从现场收集施工数据。我已经用谷歌搜索了这个废话,但我无法弄清楚将 html 元素保存在数组中是否合法(或者我的语法是否正确)。
我知道有六种方法可以获取 session.save_path 指令的值(phpinfo()、session_save_path()等),但当值为空字符串时(默认情况下为空字符串),实际路径可以是多个位
我知道 npm 库在安装时可以在分层树中安装同一库的多个版本,如下所示: a@0.1.0 -> b@1.0 -> c@2.0 -> b@2.0 在上面,版本0.1.0的包a被拉入
我是一名优秀的程序员,十分优秀!