Thursday, October 20, 2005

Inline functions optimization - answered.

Below is a simple copy-paste of the answer provided in comments of this post's question. The credit goes to Eklavya.
The reason the compiler has been given the control is because programmers can be sloppy and can thus take uninformed decisions w.r.t to making functions inline. The idea behind inline functions is to avoid the overhead associated with the creation of new frames for functions that are small say less than 10 lines or so. It would be best to execute them inline.
Now say if a programmer is given such control and he/she marks a very big function as inline, imagine the amount of code bloat that would ensue as a result esp. if that function was invoked at several places in the code. This would increase the size of our executable image with the same copy of the function lying at several places. The basic idea behind using functions would be lost. Such functions would never be inlined by the compiler.
Although, it should be noted that if the same function is invoked only once during the entire execution of the code, it would make sense to make it inline. Hence although the programmer is allowed to request for inline privileges, its only the compiler that should take the decision. Comments/suggestions/rants welcome!

0 Comments:

Post a Comment

<< Home