Author: Sune Fischer
Date: 01:44:11 03/28/02
Go up one level in this thread
On March 27, 2002 at 21:27:54, Ratko V Tomic wrote: >>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. Hmm, I think I understand what you are saying, but I'm not bundling global variables into classes. If I have a class member it's because I need to have multiple instances, in C it would have been a struct anyway. I see that you need to fetch the pointer and toss it to the function, but how is it different from C where you pass the pointer manually in the argument list? Are you saying that it can be done in C without a pointer? >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. That wouldn't surprise me a bit, still it won't be necessary if there is only one instance of the function(?). I know the idea of C++ is to overload the functions, but are the C++ compilers really so primitive they can't tell if there are multiple instances or not? >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). You have failed to convince me that this should be a bad thing, it actually sound like an optimization to me. The compiler knows that we'll be working on the object for quite a while (while in the member function), so we might as well stick the pointer in a register. I C you need to reload the same pointer over and over again. -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.