Function call Overhead:
When a function is called, a function call and return are required. You need to save the context information of the current program so that after the function call is completed, the original location is returned and the program continues to be executed. Apply the function parameters to the stack, exit the stack, and execute the function. After the function is called, the memory occupied by the internal variables is released.
Inline:
Declaring a function as inline is a suggestion for the compiler. the compiler can choose not to execute inline. Most compilers perform inline during compilation. Therefore, the virtual function cannot be inline, because the compiler does not know which function to call during compilation. The compiler does not implement inlining for calling through function pointers.
Do not perform inline on constructor and destructor easily, because even if the function body is empty, the internal compiler will generate some code, such as adding a default constructor, by default, the constructor is copied.
When a function is declared as inline, the compiler does not regard it as a function, but similar to copying the function code to the original place, thus saving the overhead of function calling.
Limit most inlining to small and frequently called functions. Inline functions copy code in every place where a function is called, which will expand the generated code. For a function, the speed of obtaining this function will be very small or even not. Therefore, do not perform inline for recursion or loops.
The inline function should put the Declaration and definition together, otherwise it will have no effect. Function definitions within the class are automatically extended to inline. The inline statement must be explicitly added outside the class.
The inline function is usually placed in the header file.
Most debuggers are helpless with the inline function, because it is not easy to set breakpoints in a non-existent function.