Is there a way to resize a std::vector to lower capacity when I no longer need previously reserved space?
Is there a way to resize a std::vector to lower capacity when I no
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Effective STL, by Scott Meyers, Item 17: Use the
swaptrick to trim excess capacity.After that,
personsis ‘shrunk to fit’.This relies on the fact that
vector‘s copy constructor allocates only as much as memory as needed for the elements being copied.