c++ Vector, what happens whenever it expands/reallocate on stack?

后端 未结 7 757
情深已故
情深已故 2020-11-29 00:51

I\'m new to C++ and I\'m using the vector class on my project. I found it quite useful because I can have an array that automatically reallocates whenever it is necessary (

7条回答
  •  心在旅途
    2020-11-29 01:30

    A vector is not an array of elements, or the memory used to store such.

    A vector manages an array of elements, the memory for which it allocates, de-allocates, shrinks and grows as required.

    Your choice of how you allocate the vector itself has no connection to the vector's own decisions about how and where to allocate the memory it manages for you.

    I don't want to discourage your interest in how the vector works internally (it's both interesting and useful), but ... the whole point of writing classes and documenting them is that you only need to understand the interface, not the implementation.

提交回复
热议问题