PDA

View Full Version : How time consuming is a d-pointer access?



pospiech
8th June 2010, 09:24
I had a discussion with a college who argued that d-pointers should never be used in any time critical situations because it would include so much overhead. I use d-pointer a lot because it makes compilation of large projects simpler.

Now I have a very simple example where time is not very critical, but I would like to have an idea what the difference is and if it would be worth not to make the variables members of a d-pointer.

The class is used to store 10 bit and greater image data and I convert back to QColor:



QColor QRgbMatrix::operator()(int x, int y)
{
int r = int(d->red[ArrPos(x,y)] * d->bitsPerPixelCorrection);
int g = int(d->green[ArrPos(x,y)] * d->bitsPerPixelCorrection);
int b = int(d->blue[ArrPos(x,y)] * d->bitsPerPixelCorrection);

if (d->isMonochrom) {
return QColor(g,g,g);
} else {
return QColor(r,g,b);
}
}


This has function calls for position, isMonochrome, red, blue and green array and the bitsPerPixelCorrection.
If I wanted to create a pixmap or an image I would loop over the whole array with this function.

Matthias

tbscope
8th June 2010, 09:42
This has zero impact.
Especially when the compiler can optimise this. If you write d->someThing or myClass->item->anotherItem->yetAntoher->someThing, the compiler just uses the memory adres of the thing you're pointing to.

pospiech
8th June 2010, 09:47
This has zero impact.
Especially when the compiler can optimise this. If you write d->someThing or myClass->item->anotherItem->yetAntoher->someThing, the compiler just uses the memory adres of the thing you're pointing to.
If this really has no measureable impact I would continue to rely on d-pointers.

tbscope
8th June 2010, 09:54
d pointers are usually used in public api's, like the Qt library to hide private functions from the user.