inline syntax
Define the method in the class declaration;
The inline method is placed outside the class declaration, but must appear in the header file, and the inline identity is used in the inline method declaration;
Note: Inline is only a suggestion to the compiler, whether inline decision right in the compiler;
Cost of inline savings
Function call Overhead
Optimized compiler between calls but the bounds of the inline method are indistinguishable (after the code is inline, the code is rearranged)
Problems associated with inline
Code bloat (space overhead)
Page cache Hit rate drop due to code bloat
Compile time increase
After modifying the file, the related files need to be recompiled;
Because the function boundary is fuzzy, the inline function is difficult to be checked after encountering the problem;
Suggestions for inline functions
optimization, only for high-frequency code inline;
For a high frequency (80% of the scenarios will go to the path):
Function scale <5 line: always inline;
5-20 lines, the high frequency of call points selectively inline;
More than 20 lines, overriding the method, reflecting the fast path and the inline;
The technique of inline
Put inline work in the late development cycle
Using conditional inline, the technique of macro and compilation options is not inline at the beginning of development, and then the custom inline option is added to the later development.
Inline in a SPARC architecture
SPARC has sufficient registers, in the limited call depth range of almost no call to return the performance loss (no need to store the contents of the register at the time of the call), all, this architecture of the inline effect is very little, generally do not consider inline;
The above mentioned is the entire content of this article, I hope you can enjoy.