Relationship between auto_inline, inline, and Compiler Optimization

Source: Internet
Author: User

Http://blog.csdn.net/pendle/article/details/5958401

During inline processing of functionsProgramAn optimization method can reduce the overhead of calling a function. This method is applicable to a large number of small functions that are frequently called. Because the function content is copied to the place where each function is called, will increase the size of the compiled binary file.

The specific process of inline processing is that during compilation, for a function that can be inline, the content of this function is directly replaced by the content of this function in every place where this function is called, therefore, the function body of this function is not generated by default.

Here is my summary:

1. the first thing to understand is that inline behavior exists only when the compiler enables Optimization Options. For example, G ++ does not perform any inline processing in-O0;

2. whether it is the # pragma auto_inline (ON/OFF) or the inline command, it is only the inline suggestions for the compiler. The Compiler determines whether to execute the inline command; any compiler can perform inline processing on the program during optimization. For the-O2 optimization method, the compiler uses heuristicAlgorithmDetermine whether it is worthwhile to perform inline on a function, and ensure that the size of the generated file is not significantly affected. The-O3 mode does not consider the size of the generated file.

3. When the # pragma auto_inline (off) command is used, inline processing of the function is disabled. At this time, even if the inline command is added before the function, inline processing is not performed on the function.

4. When the definition of a member function of the class is directly written in the class declaration, it is considered as an implicit inline request, and the compiler will automatically process the inline. In the. h file, the member function declaration of the class is defined in the. C or. cpp file, and inline processing is not performed. This is because the inline processing is performed during compilation, and the member function is called. the CPP file will only include the header file of that class. The definition of the member function cannot be found during compilation. I can see someone on the internet saying yes, but I can't try it. The undefined reference error will be reported when the inline command is added.

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.