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.