Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: OOP - Is this possible?

Author: Sune Fischer

Date: 12:21:51 03/27/02

Go up one level in this thread


On March 27, 2002 at 14:23:59, Tom Kerrigan wrote:

>On March 27, 2002 at 12:22:13, Frank Schneider wrote:
>
>>Hi,
>>
>>On March 27, 2002 at 06:25:12, Arshad F. Syed wrote:
>>
>>>I plan to write a chess program. I was wondering if it would be worthwhile to
>>>use the OOP approach. I have visited some sites of chess programs using OOP. The
>>>general consensus is that OOP would cause a big hit on the NPS.
>>
>>i don't think so. Putting code into c++-methods instead of
>>c-functions does not make it slower. Of course you should be
>
>Actually, I saw a ~10% performance hit when moving functions into classes with a
>program I was working on a while back. I assume it's because of the extra "this"
>argument that gets passed around.

But actually, the 'this' pointer is implied, the complier _know_ it is there and
it knows the specific object on which function is working.
In C, you have to use the indirection operator '->' all the time.
Even if you have to the access the object 100 times in a row:
board->...;
board->...;
...
the compiler still needs to do the indirection _everytime_, or so it seems.

I would think, that in principle C++ could be faster here since the indirection
can be done once and for all when you do board.MakeMove() or whatever...

BTW, I did this, and did not see any decline in speed, what compiler where you
using? I think the quality of C++ compilers can be very large, the language is
so much more complex than C.

>-Tom



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.