std::vector and std::string reallocation strategy

前端 未结 4 1405
南方客
南方客 2021-01-17 23:03

What is the reallocation strategy used for std::string and std::vector in GCC\'s implementations?

I\'m interested in the specific strategy employed: When I append it

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 23:43

    All bets are off on how exactly reserve works. You use it something like this:

    std::vector myV;
    myV.reserve();
    

    so you know reserve won't have to be called (nor any re-allocation performed) until after that space is exceeded.

提交回复
热议问题