PDA

View Full Version : QVector QVarLengthArray speed question



TheKedge
22nd January 2007, 10:14
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 ...


QVector<short> vector (1024);
for(int i=0; i<vector.size();++i){
someShort = vector.at(i);
or
vector[i] = i;
}

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

wysota
22nd January 2007, 10:28
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.


inline int size() const { return d->size; }