Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: OOP - Is this possible?

Author: Ratko V Tomic

Date: 18:27:54 03/27/02

Go up one level in this thread


>Whether you do:
> board.MakeMove(..) or MakeMove(board,...) it is still a
> reference/pointer you need to work with.

In that example the difference may occur in how the 'board'
variable (which is a class or structure ptr) is accessed.
The higher level class (the one making the call to board.MakeMove())
may have 'board' pointer as its data field, in which case the
C++ compiler would assume that there could be multiple instances
of this higher level class and the code would thus have to fetch
a pointer to the particular instance before it could retrieve variable
'board'. You can roughly simulate this overhead in C by bundling
the global variables into the structures and instead of accessing them
as globals, access them only via the pointer to that structure type.
While this allows you to have multiple instances of these variables,
you may be paying price for flexibility you may not always need.

Similarly, you'll find that calls to member functions are often done
via indirect call via a function pointer (stored in the implicit data
field of the class), which are more expensive than the immediate x86
calls to a fixed function. Again, you're paying the price for the
flexibility to subclass the member functions, which in many case you
would not need at all.

You can check all this on the asm output of the compiler for
some examples from your code to see how the ECX register gets
almost always reserved for 'this' pointer, making it out of
limits for other more beneficial immediate use (in addition to
the overheads of the above indirections).

It is true that with a careful design of the classes one can avoid
much of the overhead. The problem is that in real life one often
doesn't have time to think through every detail in advance. This
is especially true for creative work, where you break the new
grounds and do things you (or others) have never done before. You
can't forsee how exactly the variables and operations will relate
and interact  when all is done. You may not even know what variables
and functions will ultimately do in the solution you're still
searching for.

C++ is good for tasks you have done few times before, or for
designs created by someone who has done them before and is handing
them down to the coders for implementation i.e. it is a language
for industrial style, group think, tightly constrained corporate
assembly line programming. C is more suitable for lone wolf
creative work.




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.