c++ - Why doesn't std::vector::resize() deallocate the memory when you want to reduce the size of the vector? -


I do not understand why I use std :: vector :: swap () Why

wants to reduce the size of any vector and delete the vector memory on it at the same time all the other unused Allocate to memory?

Reducing the capability of a vector

  • New storage
  • Copying existing elements
  • Removing old storage
  • None of these are free. Actually he has the cost of shrinking vector, and it is not clear whether the users should give it by default.


    Comments

    Popular posts from this blog

    sql - Find last match with latest inserted name in table -

    c# - XML serialize base class without knowing derived class -

    ios - Invalid IPA: missing embedded provisioning profile. Are you sure this is an ad hoc? -