Clear pros and cons, use good inline

Source: Internet
Author: User
Tags call back
Clear the pros and cons, use the inline inline syntax.
  1. Define the method in the class declaration;
  2. 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
  1. Function call Overhead
  2. 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
  1. Code bloat (space overhead)
  2. Page cache Hit rate drops due to code bloat
  3. Compile time increased
  4. The relevant files need to be recompiled after the file is modified;
  5. 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
  1. Put inline work late in the development cycle
  2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.