Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Question for compiler gurus

Author: Mario Antonio F.

Date: 08:24:13 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.
>
>Thanks
>Dan H.

Without the inline hint:

The first form of call with simple integers implies a copy of square1 and
square2 into the stack.

The second call will put into the stack pointers to the parameters. Internally
there will be pointer dereferences every time you use the parameters.

Since the sizeof(int) and sizeof(int &) are comparable, the first form should be
faster than the second since there is no pointer dereference.

With the inline hint:

Both calls should be comparable, but I would not personally take chances and
would go for the first form (i.e. do not always trust the optimizer; inline is a
hint that may not be enforced).

Mario Antonio



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.