Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inlining for optimization

Status
Not open for further replies.

areza123

Programmer
Jul 4, 2002
60
IN
For optimized coding I use the following guideline:
Inline methods that - have no loops, are non virtual, are non-recursive, are not (esp.derived) class constructors / destructors and do not make calls to virtual functions.

The important point missing here is a specification on the number of lines of code the inlined function should contain. Initially I thought I would inline only those methods that contained at most 7 lines of code. This includes the length of functions that would be called from my inlined function. Is this spec ok ? I am looking for a second opinion - may be based on some mathematics.

Cheers
 
I follow this small guidline (not based on math, sorry):

Based on the paradigm of encapsulation:
Use implicit (ie implementing in the class header) inline if and only if it is a minimal function, ie basically just a return statement. I'm definately against cluttering the class' interface with implementation details, but I think simple returns are reasonable.

Based on focus on what is important:
Use "normal" inline if it is proven or very likely that the gain of inline is measurable. Typically on a few time critical every-so-often called functions.
If they are really-really time critical - consider if inline assembler will gain performance.







/Per

if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top