On the inline _c language in VC + +

Source: Internet
Author: User

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.

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.