ç内联函数和内存使用 [英] C Inline Functions and Memory Use

查看:254
本文介绍了ç内联函数和内存使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我用内联函数,确实内存使用量增加?

If I use inline functions, does the memory usage increase?

推荐答案

有两种内存使用的是内联函数会影响:

There are two kinds of memory usage that inline functions will affect:

code尺寸—一般来说,内联code会增加多少内存用于加载程序。这是因为会有散落程序生成的code的多个副本。然而,这并不总是正确的 - 如果你的内联函数只使用一次,几乎没有变化,如果内联函数是非常小的,你可以通过删除函数调用的开销得到code尺寸净减少。此外,该功能可在尺寸由这能够消除code,这不是在特定的内联调用中使用的优化减少了。

code size — in general, inlining code will increase how much memory is used to load your program. This is because there will be multiple copies of the generated code scattered around your program. However, this isn't always true -- if your inlined function was only used once, there's little change, and if the inlined function is very small, you could get a net reduction in code size by removing the function call overhead. Also, the function may be reduced in size by the optimizer that's able to remove code that's not used in the particular inline invocation.

堆栈使用—如果你的内联函数有很多局部变量,那么你可能会使用更多的堆栈空间。在C中,编译器通常用于分配在进入该函数一次函数的栈空间。这必须大到足以容纳所有未存储在寄存器中的局部变量。如果你调用一个函数外的行,堆栈该功能用于直到它返回,当它再次释放。如果内联函数,那么堆栈空间将继续用于尤伯杯功能的整个生命周期。

stack usage — If your inlined functions have lots of local variables, then you may use more stack space. In C, the compiler usually allocates the stack space for a function once upon entry to the function. This has to be large enough to hold all the local variables that aren't stored in registers. If you call a function out-of-line, the stack for that function is used until it returns, when it's released again. If you inline the function, then that stack space will remain used for the whole life of the uber-function.

内联不会影响到堆的使用情况,为同一分配和释放将发生的内联code作为可能发生的非内联版本。

Inlining won't affect heap usage, as the same allocations and deallocations would occur for the inlined code as would occur for the non-inlined version.

这篇关于ç内联函数和内存使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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