Vector clear vs. resize

前端 未结 4 1938
谎友^
谎友^ 2020-12-15 07:59

I read on the Internet that if you are clearing a std::vector repetitively (in a tight loop), it might be better to use resize(0) instead of

4条回答
  •  盖世英雄少女心
    2020-12-15 08:11

    This sound implementation specific, and is a job for you, your library and a profiler. But as I see it, I cannot see why resize(0) should be quicker when both will in effect have to call erase(begin(),end()).

提交回复
热议问题