How time consuming is a d-pointer access?
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:
Code:
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) {
} else {
}
}
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
Re: How time consuming is a d-pointer access?
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.
Re: How time consuming is a d-pointer access?
Quote:
Originally Posted by
tbscope
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.
Re: How time consuming is a d-pointer access?
d pointers are usually used in public api's, like the Qt library to hide private functions from the user.