C + + inline functions
inline functions, which look like functions, action-like functions, and no side effects of macros, can call them without the extra overhead of function calls. How good inline functions
In fact, getting more than you think, the extra overhead of avoiding function calls is just part of its benefits. The compiler can also use the optimization mechanism (which is designed to condense code that does not contain function calls), so when a function is inline, the compiler may be able to perform context-sensitive optimizations on it.
However, function calls increase the size of the target code, however, if the body of the inline function is small, the code that the compiler produces for the ' function body ' may be smaller than the target code produced by the ' function call '.
Summarize:
Advantages of inline functions:
1 No side effects of macros
2 No additional overhead for function calls
3 compiler optimizes code with optimization mechanism
Disadvantages:
It may be that the target code is enlarged, so when used, the function body must be small enough
Use Note:
1 Inline declaring a function as an inline function is just a request to the compiler, not a mandatory
2 The definition of a function is inline by default within the class definition
3 destructors and constructors are often bad candidates for inline (think about what the destructor is doing)
4 The inline function is inline also depends on how it is called
such as: inline void fuc () {}
typedef void (*PF) ();
PF PF = fuc;
FUC (); inline, Normal call
PF (); //Not necessarily inline, called by a function pointer
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Summary of C + + inline functions