On Sun, Dec 29, 2013 at 8:10 PM, Jiergir Ogoerg <[email protected]> wrote: > 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.
But... is this your *real* code? Can't you instead do QVector<my_struct> v(count); fillFromFile(v.data(), count); or use std::copy or similar? -- Giuseppe D'Angelo _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
