Author: Andrew Platt
Date: 08:29:49 10/01/04
Go up one level in this thread
On October 01, 2004 at 10:58:43, Dan Honeycutt wrote: >If I have an inline function, ie: > >_inline int Distance(int square1, int square2) > >which is going to return the max rank/file difference but is not going to alter >the arguements, would I be better off passing the arguements by reference, ie: > >_inline int Distance(int & square1, int & square2) > >so as to save having to make a copy of the arguements. Or would the compiler >figure that out on it's own since the function is inline? I'm using MS VC 6. If the function gets inlined then they will be equivalent. If they are not inlined it's pretty much impossible to tell which will end up faster. It will depend on where the variable is in the calling routine. If it's in a register it might just need to copy the value into the register used for passing the value; on the other hand it might need to flush that to the stack before calling. Passing by reference will mean that the routine will have to de-reference which could end up being more expensive if it could have just used the register value directly. For really trivial routines (and this sounds like one) it may be better to just #define it. Then there is no argument about whether the compiler will honor the _inline or not! Andy.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.