Referring to the Gotw 54 article from HerbSutter, he explains
The right way to compress-paste a vector or deque and
The right way to completely clear a vector or deque
Can I use container.resize()it container.clear()for the above task or am I missing something?
container.resize()
container.clear()
, : size Vs capacity. resize , , ( ) . resize - , , , .
size
capacity
resize
, .
size == how much you are using capacity == how much memory is reserved vector<int> v(10); v.resize(5); // size == 5 but capacity (may or may) not be changed v.clear() // size == 0 but capacity (may or may) not be changed
, , / . , " , .
resize(), clear() . .capacity() , , , size() , , reserve() d. , . capacity() , , size() reserve().
.capacity()
size()
reserve()
capacity()
.capacity() , . . , . .
, , . . -, , . , , 2 .
. X, Y . , ( ) : , .
Source: https://habr.com/ru/post/1722663/More articles:Input Controls on the ASP.NET MVC Home Page - asp.net-mvchow to do parallel work in python - pythonBluetooth on Lazarus / FreePascal on Mac OS X - delphiHow to determine if an object can be converted to a meaningful string in C # - stringFuzzy text search: a regular expression lookup generator? - phpCakePHP application on the server? - cakephpIs there a problem with the sandcastle created .chm help file? - c # -2.0ASP.Net MVC "Волшебные струны" - Их всегда можно избежать? - asp.net-mvcIs there a Firefox plug-in that can display insecure assets that cause a “Warning: contains failed content” - securityHow to hide a value in the registry (for example, RegSide sysinternals tool) - delphiAll Articles