Vector clear vs. resize

前端 未结 4 1925
谎友^
谎友^ 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:23

    Looking at Dinkumware STL source, both effectively call erase(begin(), end());

    clear() is slightly more efficient, unsurprisingly., as it has just the one case to deal with. but I wouldn't expect it's measurable.

提交回复
热议问题