3 ms·
if you know the vector's size in advance then you would use just the operator[] + resize and not push_back + reserve. you would use push_back and reserve if yo
by je42 8y ago
if you know the vector's size in advance then you would use just the operator[] + resize and not push_back + reserve.
you would use push_back and reserve if you have a pretty good idea about the size but you can't depend on it.
- FartyMcFarter 8y agoThat has the overhead of initializing the entries (which may or may not be necessary). Apparently you can prevent this by using custom allocators, which might be a fine solution but makes the code look less idiomatic.