Is there any gain in making member functions inline?
Is there any gain in making member functions inline?
The advantage of inline functions is avoiding the overhead of calling an actual function. Such overhead includes setting up stack frames, saving registers, and such. But with large functions the overhead isn't important.
Sent from my iPadŽ
"Service of the poor and destitutes is the service of the God"
Normative Changes to ISO/IEC 9899:1990 in Technical Corrigendum 1
Incompatibilities Between ISO C and ISO C++
Thanks sunny,
There is one more querry,how long function can be so that inling it is beneficial?
It's not as simple as how long is too long to inline? I quote from the text that sunny posted.
There are no simple answers: You have to play with it to see what is best. Do not settle for simplistic answers like, "Never use inline functions" or "Always use inline functions" or "Use inline functions if and only if the function is less than N lines of code." These one-size-fits-all rules may be easy to write down, but they will produce sub-optimal results.
Sent from my iPadŽ
Just adding
The inline keyword tells the compiler that inline expansion is preferred. However, the compiler can create a separate instance of the function (instantiate) and create standard calling linkages instead of inserting the code inline. Two cases where this can happen are:
Recursive functions.
Functions that are referred to through a pointer elsewhere in the translation unit.
"Service of the poor and destitutes is the service of the God"
Normative Changes to ISO/IEC 9899:1990 in Technical Corrigendum 1
Incompatibilities Between ISO C and ISO C++