What are INLINE functions for? As in getThisValueINLINE(), that sort of thing. Should I always use them when I can? How are they different from the normal versions?
What are INLINE functions for? As in getThisValueINLINE(), that sort of thing. Should I always use them when I can? How are they different from the normal versions?
They is a fairly good chance that they will be faster. The reason is that the code to do the stuff in the "function" is generated directly in the place it happens so there is no actual function call (which is why I put it in quotes). This saves writing a bunch of registers and function call parameters and such to the stack, doing the stuff, and then restoring the stored info from the stack, and probably some other stuff. The compiler can also optimize the code as an integrated part of the surrounding code which can provide the usual benefits. Assuming it really is inlined - the compiler can decide not to inline the code if it dosn't think it will help (it's more of a hint to the compiler than an order).
Here's some more explanation. (That was the first thing that came up in a Googling of "C++ inline". I didn't actually read the whole thing, but aside from section 9.4 being somewhat convoluted it looks pretty good.) You can also check out the Wikipedia page for inline functions, or many other references you can get from Google.
By the way: compilers do function inlining on their own as part of their optimizations when set to optimize the code at some optimization level - the higher the level the more they tend to inline (unless told not to, anyway). This is, therefore, pretty much just for the human to tell the compiler that the human thinks this is a good candidate for doing this, and the compiler is more likely to do it for these functions than for functions without it specified.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.