什么是内联? [英] What is inlining?

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

问题描述

我指的是此次讨论。我从来没有在C或C ++中编写任何代码。我没有任何CS背景。然而,我已经工作作为Java开发人员5年了,现在我已经决定更多地了解CS,并做一些追赶。

解决方案

p>当执行给定的代码段时,每当调用标准函数时,执行时间稍微高于将该函数中包含的代码转储。每次包含在一个函数中的整个代码在另一端都倾向于不可缓冲,因为它显然导致代码的整个混乱。



内联通过允许您将函数声明为 inline (至少在C ++中),解决了性能和可维护性问题, ,所以当你调用该函数 - 而不是让你的应用程序在运行时跳转 - 内联函数中的代码在编译时注入每次调用给定的函数。



这种情况的缺点是 - 如果你内联大功能,你调用了很多次 - 你的程序的大小可能会显着增加(最佳实践建议只做小功能) 。


I am referring to this discussion. I have never written any code in C or in C++ . I do not have any CS background. However I have been working as Java developer for 5 years and now I have decided to learn more about CS and do some catching up.

解决方案

When executing a given piece of code, whenever you call a standard function the execution time is slightly higher than dumping there the code contained into that function. Dumping every time the whole code contained in a function is on the other end unmainteinable because it obviously leads to a whole mess of duplication of code.

Inlining solves the performance and maintainability issue by letting you declare the function as inline (at least in C++), so that when you call that function - instead of having your app jumping around at runtime - the code in the inline function is injected at compile time every time that given function is called.

Downside of this is that - if you inline big functions which you call a lot of times - the size of your program may significantly increase (best practices suggest to do it only on small functions indeed).

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

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