Quick A: Because if you're serious about performance, you'll often (not always) use contiguous arrays.
From SO:
Why is std::vector contiguous?
Besides the fact that the standard defines it to be contiguous, why is
std::vector
contiguous?If it runs out of space, it needs to reallocate a new block and copy the old block to the new one before continuing.
What if it wasn't contiguous? When the storage fills up, it would just allocate a new block and keep the old block. When accessing through an iterator, it would do simple
>
,<
checks to see which block the index is in and return it. This way it doesnt need to copy the array every time it runs out of space.Would this really work/be better? or am i missing something?
Add a Comment
Comments are closed.