Hello!

In copying some large data (lets say from an array) to a QVector, what should be faster?

Option 1:
Qt Code:
  1. for (int aaa = 0; aaa < SIZE_TO_COPY; aaa++)
  2. {
  3. myVector.append(myArray[aaa]);
  4. }
To copy to clipboard, switch view to plain text mode 

Option 2:
Qt Code:
  1. const int startPoint = myVector.size();
  2. const int lastPos = startPoint + SIZE_TO_COPY;
  3. myVector.resize(lastPos); //(myVector.size() + SIZE_TO_COPY)
  4.  
  5. for (int aaa = startPoint, bbb = 0; aaa < lastPos; aaa++, bbb++)
  6. {
  7. myVector.replace(aaa,myArray[bbb]);
  8. }
To copy to clipboard, switch view to plain text mode 

Modifier 1: Include myVector.reserve(myVector.size() + SIZE_TO_COPY); before the loop in the first option or before the resize() in the second option.
Modifier 2: Use foreach(...) instead of for(...).

Thanks,

Momergil