How is C++ std::vector implemented?

后端 未结 9 1357
不思量自难忘°
不思量自难忘° 2020-11-28 06:49

I have been using std::vector a lot, and recently I asked myself this question: \"How is std::vector implemented?\"

I had two alternatives:

9条回答
  •  余生分开走
    2020-11-28 07:47

    I believe the STL uses option #2 (or something similar) because a std::vector<> is guaranteed to store the elements in contiguous memory.

    If you're looking for a memory structure that doesn't need to use contiguous memory, look at std::deque.

提交回复
热议问题