Need for inline functions

9:07 PM 0 Comments

TO understand why inline fuction is needed
firstly, we have to understand what happen when funcion is called
from figure:
when function is called the CPU stores the memory address of the instruction following the function call(RIP)
return instruction pointer, then  copies the arguments of the function on the stack and finally transfers control to the specified function then executes the function code
AFTER FUNCTION EXECUTION THE EIP GOES TO RIP;
This can become overhead if the execution time of function is less than the switching time from the caller function to called function (callee)
FOR larger function this overhead is negligible
but for small functions the time needed to make the function call is often a lot more than the time needed to actually execute the function’s code

This overhead occurs for small functions because execution time of small function is less than the switching time.
C++  provides
inline functions to reduce the function call overhead

Unknown

Live as if you were to die tomorrow. Learn as if you were to live forever.

0 comments: