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
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