How is dynamic memory managed in std::vector?

后端 未结 4 1548
南笙
南笙 2021-01-03 08:52

How does std::vector implement the management of the changing number of elements: Does it use realloc() function, or does it use a linked list?

Thanks.

4条回答
  •  灰色年华
    2021-01-03 09:26

    The memory managed by std::vector is guaranteed to be continuous, such that you can treat &vec[0] as a pointer to the beginning of a dynamic array.

    Given this, how it actually manages it's reallocations is implementation specific.

提交回复
热议问题