So, if I reserve (100) first, add some elements and then resize (0) (or any other number smaller than the current size), will the vector reallocate memory to less space than 100 elements?
vector<T>::resize(0) should not cause a reallocation or deletion of allocated memory, and for this reason, in most cases, vector<T>::clear() preferable.
vector<T>::resize(0)
vector<T>::clear()
See the answers to this question for more details: std :: vector resize down
Running vector::resize(0) or a smaller count, not the current count, should not free memory. However, it can destroy these elements.
vector::resize(0)
For reference on std::vector::resize , see std :: vector :: resize
std::vector::resize
Source: https://habr.com/ru/post/913092/More articles:NSURLConnection with NSRunLoopCommonModes - iosStop Excel mouse cursor from flickering above a button - user-interfaceOpen a new dialog from a dialog in qt - qtWhy doesn't Collections.frequency work as expected in the converted list? - javaUsing smart pointers in a structure or class - c ++Apache HTTPD / mod_proxy / Tomcat and SSL with client authorization - sslUsing SelectByText (partial) with C # Selenium WebDriver bindings doesn't work - c #Is there any documentation for dropping zeros in decimal decimal notations of IPV4 addresses? - rfcCode Templates - Element Name Collision Between Delphi Versions - delphiWhat is EOL (End of Life) for Rails 2.3? - ruby-on-railsAll Articles