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