Qt 6: Move QList contents without copying?
-
@Christian-Ehrlicher said in Qt 6: Move QList contents without copying?:
It moves the data from memory a to memory b. It's just not a copy but a move operation. Nothing more.
For this purpose I am calling that "copy" because (does it not?) have to copy the elements (in the
QList
, not what they might point to) from memory area a to area b? Certainly if iterates that is O(n), I don't know whether you mean CPUs have an instruction to do that fast instead? Think about if it appends a list of 1,000,000 items to an existing list of one item. Moving and appending a list (like a linked list) could be made an O(1) operation, but not with the vector implementation of Qt6QList
, that is my point. I think of "copy" for O(n), "move" to me implies O(1) (hopefully). Is this not correct?@JonB said in Qt 6: Move QList contents without copying?:
Think about if it appends a list of 1,000,000 items to an existing list of one item. Moving and appending a list (like a linked list) could be made an O(1) operation
Well, you are right about that. However, I would expect that something would be done with the data afterwards. Iterating over the elements of a linked list and the elements of a vector is both O(n). Still, in the general case a vector will be faster because of consecutive memory whereas a list might have many cache misses. If iteration is done more than once the vector might be faster (after copying 1,000,000 items). It is a very tricky problem.