Macro, we sometimes define some preprocessing macros, such
# Define comp (x)> 0? (X): 0) defines a macro.
The reason for macro usage is that function calls have a certain amount of time and space overhead (when the function call user jumps to the address in the memory of the function, after the execution, it jumps back to the original position to continue the execution. This transfer requires saving the scene and remembering the current memory location, and restoring the scene after the function is executed), while the macro only expands the code in the pre-processing place without additional time space overhead, therefore, the efficiency is improved.
Inline functions are defined using inline. functions that define the function body within the class are called inline functions by default.
Inline functions are the most widely used in C ++ classes and should be used to define access functions. Generally, data members are defined as private or protected in the classes we define. In this way, the outside world cannot directly read and write the data of our class members. Read/write operations must be performed using the member interface function. If we define these read/write member functions as inline functions, the efficiency will be better.
Class test {
PRIVATE:
Int test;
Public:
Int gettest () {return test ;}
Void settest (INT t) {test = T ;}
}
The difference between an inline function and a macro is that a macro is replaced by a Preprocessor, while an inline function is implemented through compiler control. In addition, inline functions are real functions, but they are expanded like macros when needed. Therefore, the parameter pressure stack of the function is removed, reducing the call overhead. You can call inline functions like calling functions without worrying about macro processing issues.
Of course, inline functions also have some limitations. That is, the Execution Code in the function cannot be too much. If the function body of the inline function is too large, the general compiler will discard the inline method and call the function in the normal way. In this way, the efficiency of inline functions is the same as that of normal functions.
Extracted from http://blog.csdn.net/longjing1113/article/details/8807671
Inline functions and macros