Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: OOP - Is this possible?

Author: Sune Fischer

Date: 17:01:06 03/27/02

Go up one level in this thread


On March 27, 2002 at 18:40:57, Ratko V Tomic wrote:

>> 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.
>
>The 'this' pointer is a pointer to an instance of the class, so
>the compiler has to load and use-up a register (ecx on VC) to access
>the class variables for a given instance. This C++ indirection and
>the register usage is on top of any other indirection that is common
>to C and C++. You would almost have to use C++ like C (e.g. not use
>class instantiated variables in any time critical functions) to
>avoid using-up of the register for 'this' (which on x86 processor
>is expensive since it has so few registers).

Okay, but what I don't understand is how you avoid a similar thing in C.
Whether you do:
board.MakeMove(..) or MakeMove(board,...) it is still a reference/pointer you
need to work with.

And in C, you need to do use the member selector "->" also (if it is a struct).
So I see no difference, other than in C++ you can express yourself clearly to
the compiler by saying: "hey dude, this is the object we will be working on now,
okay". If the C++ compilers aren't able to use this bit of information too bad,
but in principle it is more strict than C, where the pointer could point all
over the place. At least we know "this" it is a constant pointer, in C we know
nothing about, what is basicly, the same pointer.

-S.



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.