Talk about inline in VC++
- 2020-04-02 03:08:39
- OfStack
Inline syntax
Define methods in class declarations;
Inline methods are placed outside of the class declaration, but must appear in the header file, and inline method declarations are identified by inline.
Note: inline is only a suggestion to the compiler, the decision whether inline is up to the compiler;
Savings from inlining
Function call overhead
Good inter-invocation compilers can be hard to distinguish the boundaries of inline methods (inlining the code and rearranging it)
Problems with inlining
Code bloat (space overhead)
Page cache hit ratio decreases due to code bloat
Compile time increased
After modifying files, relevant files need to be recompiled;
Because the boundary of the function is fuzzy, the inline function is not easy to troubleshoot after encountering problems.
Suggestions for inline functions
When optimized, only for high-frequency code inline;
For paths with high invocation frequency (more than 80% of scenarios will go to) :
Function scale
<
Line 5: always inline;
Line 5-20, the high frequency of the call point selected inline;
Over 20 lines, rewrite the method to show the fast path and inline it;
Inline technique
Put inline work later in the development cycle
Use conditional inline, control not to inline early in development with macros and compilation options, and inline later with custom inline options;
Inline in the SPARC architecture
SPARC has an abundance of registers, and within a limited call depth range there is almost no performance penalty (no need to store the contents of the register when the call is made) returned by the call.
The above is all the content of this article, I hope you can enjoy it.