Results 1 to 19 of 19

Thread: Understanding why these few lines are slow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Understanding why these few lines are slow

    I also like foreach because its easy to use, avoids unnecessary copying and very readable and the performance is ok:

    Qt Code:
    1. foreach(const QUrl& url, event->mimeData()->urls()) {
    2. //work
    3. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Understanding why these few lines are slow

    As the documentation says
    Qt automatically takes a copy of the container
    .

    So make me correct, but isn't foreach loop something useful when iterating through the container holding pointers not entire objects, because in other way we use 2 times original_container_size amount of memory ?
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Understanding why these few lines are slow

    Quote Originally Posted by kornicameister View Post
    As the documentation says .

    So make me correct, but isn't foreach loop something useful when iterating through the container holding pointers not entire objects, because in other way we use 2 times original_container_size amount of memory ?
    It depends on the container. All Qt containers are implcitly shared so only a shallow copy of the container is made, the real data is not copied. If you create your own container (or use some 3rd party code) that doesn't share data between its copies then foreach will cause an immediate overhead in both memory and time because the container will have to be copied.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Understanding RGB888
    By scarleton in forum Qt Programming
    Replies: 6
    Last Post: 29th August 2010, 20:03
  2. Having trouble understanding brush
    By feraudyh in forum Newbie
    Replies: 4
    Last Post: 30th July 2010, 18:18
  3. Better understanding of the ModelView archtecture
    By scarleton in forum Qt Programming
    Replies: 6
    Last Post: 28th June 2010, 07:07
  4. Help understanding QWT Contour Plot
    By jwieland in forum Qwt
    Replies: 11
    Last Post: 7th December 2009, 06:47
  5. I need help understanding QGraphicsView
    By aarelovich in forum Qt Programming
    Replies: 13
    Last Post: 22nd July 2009, 20:02

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
  •  
Qt is a trademark of The Qt Company.