Jump to content
  • Advertisement
Sign in to follow this  
Kenny77

Inline Functions

This topic is 4166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been reading about inline functions and their advantages, but my book doesn't cover the disadvantages, so what are they?

Share this post


Link to post
Share on other sites
Advertisement
inlining larger functions can cause your exe to be larger in size then necessary, if programming for a device with low hardware requirements you might not want that. It could also slow a larger function because the function call itself may be faster if it were not inlined. So its best used for smaller functions containing one or two lines.

Share this post


Link to post
Share on other sites
Increased code size, which can mean more memory use (both total and time spent accessing thing that have fallen out of cache). Generally, the bigger the function, the less likely it's a good idea to inline it. The opposite also holds true (that the smaller it is, the more likely your compiler will inline it for you on the assumption that it's probably a good idea).

Share this post


Link to post
Share on other sites
Yes, increased function size can really lead to thrashing. As a result most compilers have options that control the maximum size of a function that can be inlined. GCC has -fno-default-inline -fno-inline -finline-functions and -finline-limit=N. All the games I have worked on recently have shipped with -Os enabled (optimise for size). Visual C has equivalents that I cannot be bothered to fish out of the online browser-thrashing horror that is MSDN.

Share this post


Link to post
Share on other sites
Also, not all functions can be inlined. This is true for recursive functions and dynamic dispatch functions.

Share this post


Link to post
Share on other sites
Having inline functions in header files could increase compile time too. If you change the implementation of the inline function the client code will need to be recompiled, instead of just the function's source if the function weren't inlined.

Share this post


Link to post
Share on other sites
Quote:
Original post by rip-off
Having inline functions in header files could increase compile time too. If you change the implementation of the inline function the client code will need to be recompiled, instead of just the function's source if the function weren't inlined.

In a large library, that's definitely something that can cause suffering.

I just remembered a detail about binary compatibility. Inline functions in a dynamically linked library can break binary compatibility with a compiled application, since the function definition can be changed in the library, but the old code will be executed by the compiled application since there's no call. The drawback of that is that it might not be possible to update the library without recompiling the applications that use it.

Share this post


Link to post
Share on other sites
There is drawback to inline functions that nobody mentioned. When you make a function inline, you must expose implementation details that would normally be hidden. Problems can include circular dependencies, private functions and data which must be made public, and longer compile times.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!