Hi, there are 2 simple options to speed up setting/adding elements to a vector when a heap buffer is filled in in advance: 1) Bulk copy. Assign a bunch of elements at once (from another vector or array), like std::vector::assign() does. A big extra copy happens, but avoids multiple calls to push_back().
2) Zero copy. Set the buffer of the (Q)Vector directly along with the number of elements to bypass any copying whatsoever, std::vector lacks this apparently. Apparently QVector lacks both. Would it be OK adding any or both of them? Case in point. I got a buffer on the heap: my_struct *arr = new my_struct[count]; Then the arr is filled in from a file or another source, then I could do a direct assignment without any copy and multiple callbacks to push_back(), let's call this method setBuffer(void *buf, elem_count): qtvec->setBuffer(arr, count); obviously no need to call delete[] arr after this. Because QVector doesn't have any of the 2 methods currently I have to loop thru each my_struct elements and do each time a memcpy() to a temporary variable and push_back() it to the QVector. _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
