Results 1 to 4 of 4

Thread: How time consuming is a d-pointer access?

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

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

  3. #3
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How time consuming is a d-pointer access?

    Quote Originally Posted by tbscope View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

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

Similar Threads

  1. Application consuming 60% of CPU usage ..
    By wagmare in forum Qt Programming
    Replies: 3
    Last Post: 20th October 2009, 10:23
  2. Once again: buttons and time consuming tasks
    By pampo in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2009, 18:26
  3. Replies: 2
    Last Post: 23rd April 2009, 07:15
  4. Show progress of a time consuming operation
    By rainman110 in forum Newbie
    Replies: 7
    Last Post: 10th February 2008, 12:07
  5. check the time of last time keyboard is pressed
    By Aki Tomar in forum General Programming
    Replies: 2
    Last Post: 5th February 2008, 09:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.