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

    winforms - C# Form - Property Change -

    javascript - amcharts makechart not working -

    java - Algorithm negotiation fail SSH in Jenkins -