Advantages and Disadvantages of Inline Function in C++


Advantages of Inline Function in C++

  • Function call overhead doesn’t occur.
  • It also saves the overhead of push/pop variables on the stack when the function is called.
  • It also saves the overhead of a return call from a function.
  • When you inline a function, you may enable the compiler to perform context-specific optimization on the body of the function. Such optimizations are not possible for normal function calls. Other optimizations can be obtained by considering the flows of calling context and the called context.
  • The inline function may be useful (if it is small) for embedded systems because inline can yield less code than the function call preamble and return.
Advantages and Disadvantages of Inline Function in C++
Advantages and Disadvantages of Inline Function in C++

Disadvantages of Inline Function in C++

  • The added variables from the inlined function consume additional registers, After the in-lining function if the variables number which is going to use the register increases then they may create overhead on the register variable resource utilization. This means that when the inline function body is substituted at the point of a function call, the total number of variables used by the function also gets inserted. So the number of registers going to be used for the variables will also get increased. So if after function inlining variable numbers increase drastically then it would surely cause overhead on register utilization.
  • If you use too many inline functions then the size of the binary executable file will be large, because of the duplication of the same code.
  • Too much inlining can also reduce your instruction cache hit rate, thus reducing the speed of instruction fetch from that of cache memory to that of primary memory.
  • The inline function may increase compile time overhead if someone changes the code inside the inline function then all the calling location has to be recompiled because the compiler would require to replace all the code once again to reflect the changes, otherwise, it will continue with old functionality.
  • Inline functions may not be useful for many embedded systems. Because in embedded systems code size is more important than speed.
  • Inline functions might cause thrashing because inlining might increase the size of the binary executable file. Thrashing in memory causes the performance of computers to degrade.

Read More –

Inline function – Wikipedia


Please enter your comment!
Please enter your name here