Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 6: Move QList contents without copying?
Forum Updated to NodeBB v4.3 + New Features

Qt 6: Move QList contents without copying?

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 6 Posters 3.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JonBJ JonB

    @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 Qt6 QList, that is my point. I think of "copy" for O(n), "move" to me implies O(1) (hopefully). Is this not correct?

    S Offline
    S Offline
    SimonSchroeder
    wrote on last edited by
    #21

    @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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved