Thursday, June 21, 2007

Understand the ins and outs of inlining

Compilers are designed to optimize nicely over stretches of code without function calls.

Inlining can cause code bloat -> lower hit rates,memory crunch -> bad performance
Define function inside a class also makes it inline.
Inline functions should typically be in header files. Since inlining is generally a compile type thing
Compilers choose whether to inline or not
All but the trivial virtual fns are generally not inlined.
Most compilers have a diagnostic level that will result in a warning if compiler cant mark a function inline.
If your program takes the address of a function then the body of the function wud be generated even if compiler can imline it. Even if you don't do it ,sometimes compilers might just do that.

Compilers put hteir own code in constructors and destructors for handling exception, destruction In case of incomplete construction, calling base class constructor for derived classes etc.

If u have a inline function then clients are using it  means it is in there code, so u change implementation of that fn means clients have to recompile.

One pain in coding is that debuggers have trouble with inline functions

Things to remember:
Limit most inlinking to small frequently called functions. This facilititates debugging and binary upgradablity, minimizes potential code bloat, and mizimizes the changes of greater program speed.

Don't declare function templates inline just because they appeat in header files

No comments: