为什么不标记一切内联? [英] Why not mark everything inline?

查看:215
本文介绍了为什么不标记一切内联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了减少错误的答案水平确保你明白 inline 关键字实际上意味着什么。这里是很好的描述, inline vs static vs extern

To reduce the level of misguided answers make sure you understand what the inline keyword actually means. Here is good description, inline vs static vs extern.

所以我的问题,为什么不标记每个函数定义 inline ?即理想情况下,唯一的编译单元是 main.cpp

So my question, why not mark every function definition inline? ie Ideally, the only compilation unit would be main.cpp. Or possibly a few more for the functions that cannot be defined in a header file (pimpl idiom, etc).

这个奇数请求的理论是给予优化器要处理的最大信息。它可以内联函数实现当然,但它也可以做跨模块优化,因为只有一个模块。还有其他优势吗?

The theory behind this odd request is it would give the optimizer maximum information to work with. It could inline function implementations of course, but it could also do "cross-module" optimization as there is only one module. Are there other advantages?

有没有人尝试过这个与一个真正的应用程序?性能是否提高?减少?!?

Has any one tried this in with a real application? Did the performance increase? decrease?!?

标记所有函数定义的缺点 inline

What are the disadvantages of marking all function definitions inline?


  • 编译可能会更慢,会消耗更多内存。

  • 迭代构建被破坏,整个应用程序将需要重建

所有这些缺点只会影响开发者。

All of these disadvantage only effect the developer. What are the runtime disadvantages?

推荐答案

你真的是指 #include 一切?

实际上,微软的Visual C ++在使用 / GL (整个程序优化)开关,它不会实际上编译任何东西,直到链接器运行并且可以访问所有代码。其他编译器也有类似选项。

Actually, Microsoft's Visual C++ does exactly this when you use the /GL (Whole Program Optimization) switch, it doesn't actually compile anything until the linker runs and has access to all code. Other compilers have similar options.

这篇关于为什么不标记一切内联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆