Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is inlining?

Tags:

java

c++

inlining

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.

like image 769
Roger Avatar asked Oct 10 '09 00:10

Roger


People also ask

What is inlining in programming?

Inlining is the process of replacing a subroutine or function call at the call site with the body of the subroutine or function being called. This eliminates call-linkage overhead and can expose significant optimization opportunities.

What does inlining a function do?

An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.

What is inlining method?

What Method Inlining Is? Basically, inlining is a way to optimize compiled source code at runtime by replacing the invocations of the most often executed methods with its bodies. Although there's compilation involved, it's not performed by the traditional javac compiler, but by the JVM itself.

What is inlining in C++?

Inline function in C++ is an enhancement feature that improves the execution time and speed of the program. The main advantage of inline functions is that you can use them with C++ classes as well.


1 Answers

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).

like image 155
JohnIdol Avatar answered Sep 19 '22 09:09

JohnIdol