Every single time I loop through an array inside a class, which I access via a pointer, I ask myself this very same question:
Does each iteration produce overhead by dereferencing of the pointer? Do dereference-chains add up? For example:
ClassA *a = new ClassA();
ClassB *b = new ClassB();
for( int i = 0; i < 10; i++){
a->b->array[i].foo();
}
If I had to guess, I would say this involves 20 dereference steps, one for each pointers, 10 iterations. But I could just as well imagine, that its reduced to 10 because the chained pointers are translated to a single one by the compiler. I could even imagine, that it is reduced to 1, because of some caching-voodoo or something.
Can someone tell, and maybe explain to me, how this behaves performance-wise? Would really appreciate it!
Btw, I know that kind of similar questions have already been answered here, but I was not able to deduce the answer for this specific topic. So please dont blame me for bringing up this topic again.