I've got a question about the efficiency of dereferencing pointers (well, I think "dereferencing" is the word I'm looking for). Here's my dilemma:
Say I've got four classes called A, B, C, and D. An instance of B called "b" is contained as a public member of A, an instance of C called "c" is contained in B, and so on. Let myMethod1..3 be member functions of the D class, and let a be an instance of the A class.
Now take this chunk of code:
a->b->c->d->myMethod1
a->b->c->d->myMethod2
a->b->c->d->myMethod3
My question is, will there be any speed difference between this code and manually caching the location of a->b->c->d beforehand, as follows:
D *dPointer = a->b->c->d
dPointer->myMethod1
dPointer->myMethod2
dPointer->myMethod3
So basically I'm wondering if the compiled program has to re-compute the location of a->b->c->d (by dereferencing a, then dereferencing b, then c, and then d) or not. Any help on this issue would be greatly appreciated.








