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:

Qt Code:
  1. QColor QRgbMatrix::operator()(int x, int y)
  2. {
  3. int r = int(d->red[ArrPos(x,y)] * d->bitsPerPixelCorrection);
  4. int g = int(d->green[ArrPos(x,y)] * d->bitsPerPixelCorrection);
  5. int b = int(d->blue[ArrPos(x,y)] * d->bitsPerPixelCorrection);
  6.  
  7. if (d->isMonochrom) {
  8. return QColor(g,g,g);
  9. } else {
  10. return QColor(r,g,b);
  11. }
  12. }
To copy to clipboard, switch view to plain text mode 

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