How to correctly deallocate or delete a c++ vector?

前端 未结 6 1636
灰色年华
灰色年华 2021-01-25 11:00

I have a weird problem with vector in C++..

I created a vector and inserted 10000 integer values into it and have checked the memory utilization. It is 600 kb. But after

6条回答
  •  梦谈多话
    2021-01-25 11:42

    Try using the erase-remove idiom. If you are just erasing all of the elements from the vector then all you are doing is moving the end() iterator. So everything is still there in the vector but "unavailable".

    http://en.wikipedia.org/wiki/Erase-remove_idiom

提交回复
热议问题