Does std::vector *have* to move objects when growing capacity? Or, can allocators “reallocate”?

后端 未结 3 1518
广开言路
广开言路 2020-11-27 04:33

A different question inspired the following thought:

Does std::vector have to move all the elements when it increases its capacity?

3条回答
  •  时光说笑
    2020-11-27 05:02

    When std::vector runs out of capacity it has to allocate a new block. You have correctly covered the reasons.

    IMO it would make sense to augment the allocator interface. Two of us tried to for C++11 and we were unable to gain support for it: [1] [2]

    I became convinced that in order to make this work, an additional C-level API would be needed. I failed in gaining support for that as well: [3]

提交回复
热议问题