Why is it optimal to use inline functions?

Apparent, inline functions are defined in the caller's code stream, which improves performance.

What does this mean? I wrote an inline function and it behaves just like a non-inline one. When can't a function be inline?
Inline is not a simple topic because compilers will try their best to make every function inline. I don't have the compiler knowledge to delve into the details unfortunately.

You have to understand that loops and functions were invented to help programmers, not the compiler. If all code was a single function and all loops were hard-coded you would yield the best performance but how the hell would you be able to read and maintain it? You'd be better of just writing in assembly. lol


Try looking at this topic.

http://www.cplusplus.com/forum/articles/20600/
Last edited on
When the compiler grants a function inline, it does not push an activation record on the stack like a non-inline function. It literally places the code for the function 'inline' with the caller. There are advantages and disadvantages. It can improve performance, but it can also hinder performance. It can create code bloat, by itself it doesn't seem so bad, with today's hardware, however this isn't always entirely true and I'll leave it at that.
The meaning is a whole bunch of low-level space-time optimizations.

The whole point to inlineing is this: If you have a really tiny function that gets called a lot, the overhead of setting up a stack frame, performing a call branch, function prologue, then performing a restore branch and cleanup -- it is just too much. It is easier, and probably about the same size in terms of machine instructions, just to stick the function's body in place of the call.

Hope this helps.
Topic archived. No new replies allowed.