+ 2
What is an inline function?
3 ответов
+ 5
In C++:
Inlining prevents overhead from method/function call.
Inline methods should be written in class definition (.h file).
Only small code methods/functions should be used as inline.
Compiler replaces definition of inline methods at compile time with the method code instead of referring to method definition at runtime.
Results in faster runtime, but larger compiled code.
+ 1
In Scala you can write @inline to a function definition. When the program is compiled the function gets removed and the body is copied everywhere it is called. So you have less function calls at runtime. That might speed up your program under certain circumstances.
+ 1
Inline Function (C++)
------------------------
- Commonly used for calculation.
- The function call is replaced with the function logic at the time of compilation.
- Make execution faster.
- Compiled code is relatively bigger.
inline int sum (int a=0, int b=0){
return (a+b);
}
cout<<sum(10,20); => cout<<(10+20);
Earlier in C language same can be achieved by using #define preprocessor statement. It is data type independent. On contrary, inline functions are tightly typed.