Clear the pros and cons, use the inline inline syntax.
- Define the method in the class declaration;
- Inline methods are placed outside the class declaration, but must appear in the header file, and inline is used in the inline method declaration;
Note: Inline is only a recommendation to the compiler, whether the inline decision is in the compiler;
The cost of inline savings
- Function call Overhead
- Excellent compiler for inter-call optimization but the boundaries of inline methods are difficult to distinguish (after the code is inline, the code is rearranged)
Problems with inline
- Code bloat (space overhead)
- Page cache Hit rate drops due to code bloat
- Compile time increased
- The relevant files need to be recompiled after the file is modified;
- Because the function boundary is blurred, the inline function is difficult to troubleshoot after encountering a problem;
Recommendations for inline functions
optimization, only for high-frequency code inline;
For calls with high frequency (80% or more scenarios will go to the path):
Function scale <5 line: always inline;
5-20 lines, the high frequency call point is selectively inline;
More than 20 lines, overriding the method, manifesting a fast path and linking it;
Tips for Inline
- Put inline work late in the development cycle
- Using conditional inline, the techniques of macro and compilation options are not inline in the early stages of development, but are inline with custom inline options at the end of the development period;
Inline in the SPARC architecture
There is sufficient register in SPARC, there is almost no performance loss to call back within the defined call depth (no need to store the contents of the register at the time of invocation), all of which have little inline effect, generally without regard to inline;
Posted by: Big CC | 29jun,2015
Blog: blog.me115.com [Subscribe]
Github: Big cc
Clear pros and cons, use good inline