3 ms·
> This avoids default-constructing all of the values inside of it, only to overwrite them with the new values you're copying in. I think that I saw a few bench
by jcelerier 9y ago
> This avoids default-constructing all of the values inside of it, only to overwrite them with the new values you're copying in.
I think that I saw a few benchmarks once showing that for primitive types such as int & such, it was actually more efficient to resize() ; only past 32 or 64 bytes structs did reserving' become more interesting. In any case, when nitpicking on this it's even better to use boost::vector which allows to do an uninitialized resize : http://www.boost.org/doc/libs/1_66_0/doc/html/container/extended_functionality.html#container.extended_functionality.default_initialialization http://www.boost.org/doc/libs/1_66_0/doc/html/container/exte....
- bstamour 9y agoThat's interesting, and a bit counter-intuitive IMO. But I guess that's why we measure things. The reserve operation is essentially just a single reallocation, whereas the resize is a reallocation plus a bunch of zeroing out. Strange.