加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

“热”和“内联”组合对函数定义的性能影响

发布时间:2020-12-13 19:37:54 所属栏目:Linux 来源:网络整理
导读:我有一个功能,它只进行一些操作,如增量.我已声明为内联和__attribute __((热)). Gcc Doc建议关注热门属性: The hot attribute is used to inform the compiler that a function is a hot spot of the compiled program. The function is optimized more agg

我有一个功能,它只进行一些操作,如增量.我已声明为内联和__attribute __((热)).

Gcc Doc建议关注热门属性:

The hot attribute is used to inform the compiler that a function is a
hot spot of the compiled program. The function is optimized more
aggressively and on many target it is placed into special subsection
of the text section so all hot functions appears close together
improving locality.

可以解释为非内联热函数,它们将被放置在进程地址映射的低地址区域中.但内联函数调用应该被它们的代码逐字取代.那么问题是内联和热的组合如何真正起作用?

最佳答案
有关内联关键字的详细说明,请参阅When should I write the keyword ‘inline’ for a function/method?.将函数声明为热和内联似乎是一种矛盾;如果函数未在头文件中定义,或者未在多个编译单元中定义,则不应将其声明为内联.

实际上,决定用函数定义替换函数调用并将其置于“内联”取决于编译器.所以内联和热的组合可能只是忽略内联部分并将其放在程序的text.hot部分.链接器是进程中唯一真正关心内联关键字的部分,然后它不一定按照您的想象执行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读