I am a college Computer Science student and I have been trying to understand the stl::vector on a deeper level. I found out, vector are in fact dynamic arrays, meaning upon insertion/deletion, if needed, the array is resized.
A friend told me, when the array's reallocated, for example upon insertion, instead of creating a new array of size [original+1], it creates a new array of a size [2*original].
Wouldn't it be better to only add (or substract) one array field when you insert/delete something, instead of creating an array twice as large, leaving many indexes unused?
I thought the reason for this is, that perhaps creating an array twice as large, or reallocatin the array, only every once in a while rather than on every insertion/deletion has much better time complexcity, but for example, if I had an array of large objects, would it even then be still better to reallocate an array twice the size of original, or use size+1?
Thank you for responses.