c++ - What is wrong with using inline functions? -


while convenient use inline functions @ situations,

are there drawbacks inline functions?

conclusion:

apparently, there nothing wrong using inline functions.

but worth noting following points!

  • overuse of inlining can make programs slower. depending on function's size, inlining can cause code size increase or decrease. inlining small accessor function decrease code size while inlining large function can dramatically increase code size. on modern processors smaller code runs faster due better use of instruction cache. - google guidelines

  • the speed benefits of inline functions tend diminish function grows in size. @ point overhead of function call becomes small compared execution of function body, , benefit lost - source

  • there few situations inline function may not work:

    • for function returning values; if return statement exists.
    • for function not returning values; if loop, switch or goto statement exists.
    • if function recursive. -source
  • the __inline keyword causes function inlined if specify optimize option. if optimize specified, whether or not __inline honored depends on setting of inline optimizer option. default, inline option in effect whenever optimizer run. if specify optimize , must specify noinline option if want __inline keyword ignored. -source

it worth pointing out inline keyword hint compiler. compiler may ignore inline , generate code function someplace.

the main drawback inline functions can increase size of executable (depending on number of instantiations). can problem on platforms (eg. embedded systems), if function recursive.

i'd recommend making inline'd functions very small - speed benefits of inline functions tend diminish function grows in size. @ point overhead of function call becomes small compared execution of function body, , benefit lost.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -