Q:

What is the advantage and disadvantage of the inline function?

0

What is the advantage and disadvantage of the inline function?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

There are a few important advantages and disadvantages of the inline function.

Advantages:-

1) It saves the function calling overhead.
2) It also saves the overhead of variables push/pop on the stack, while function calling.
3) It also saves the overhead of return call from a function.
4) It increases the locality of reference by utilizing the instruction cache.
5) After the inlining compiler can also apply intraprocedural optimization if specified. This is the most important one, in this way compiler can now focus on dead code elimination, can give more stress on branch prediction, induction variable elimination, etc..

Disadvantages:-

1) May increase function size so that it may not fit in the cache, causing lots of cache miss.
2) After inlining function, if variables numbers which are going to use register increases than they may create overhead on register variable resource utilization.
3) It may cause compilation overhead as if somebody changes code inside an inline function then all calling locations will also be compiled.
4) If used in the header file, it will make your header file size large and may also make it unreadable.
5) If somebody used too many inline functions resultant in a larger code size than it may cause thrashing in memory. More and number of page faults bringing down your program performance.
6) It’s not useful for an embedded system where large binary size is not preferred at all due to memory size constraints.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Interview Questions and Answers(2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What’s the difference between static, inline, an... >>
<< What is the use of the inline function in C++?...