Does std::vector::resize() ever reallocate when new size is smaller than current size? [duplicate]
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: std::vector resize downward If I resize() an std::vector to some size smaller than its current size, is it possible that the vector will ever allocate new memory? This is important to me for performance reasons. 回答1: No, resize ing to a smaller size will never reallocate. In case the container shrinks, all iterators, pointers and references to elements that have not been removed remain valid after the resize and