Results 1 to 2 of 2

Thread: QVector QVarLengthArray speed question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    29
    Thanked 3 Times in 2 Posts

    Default QVector QVarLengthArray speed question

    Hello all,
    just a quick question - apparently QVarLengthArray is faster assigining memory. But is
    QVector<> (with any assignable basic type) slower in a loop e.g. using ...

    Qt Code:
    1. QVector<short> vector (1024);
    2. for(int i=0; i<vector.size();++i){
    3. someShort = vector.at(i);
    4. or
    5. vector[i] = i;
    6. }
    To copy to clipboard, switch view to plain text mode 

    or should I make a short* from vector.data() and put the pointer into the loop?
    By the way, does the vector.size() get calculated every iteration?

    thanks
    K

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

    Default Re: QVector QVarLengthArray speed question

    Quote Originally Posted by TheKedge View Post
    But is
    QVector<> (with any assignable basic type) slower in a loop e.g. using ...
    No, lookup in QVector is O(1).

    By the way, does the vector.size() get calculated every iteration?
    No, it doesn't.

    Qt Code:
    1. inline int size() const { return d->size; }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to wysota for this useful post:

    TheKedge (22nd January 2007)

Similar Threads

  1. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 15:38

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.