[Development] OK to add zero/bulk copy to QVector?

Yves Bailly yves.bailly at laposte.net
Sun Dec 29 22:44:58 CET 2013

On 29/12/2013 20:10, Jiergir Ogoerg 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().

What about this, re-using your example:
my_struct *arr = new my_struct[count];
QVector<my_struct> v(count);
memcpy(v.data(), arr, sizeof(my_struct)*count);

Assuming "my_struct" doesn't contain self-referencing references or
virtual table.


(o< | Yves Bailly                          | -o)
//\ | Linux Dijon  : http://www.coagul.org | //\
\_/ |                                      | \_/`

More information about the Development mailing list