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.
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 –
- Dynamic Storage Allocation Techniques in Compiler Design
- Dag Representation Of A Basic Block Allows
- Brute Force Approach in Compiler Design
- Can Only Compare Identically-Labeled Series Objects
- This Vector Function Is Used To Insert An Item Into A Vector