JTK JTK - 1 year ago 100
C++ Question

In C++, does a vector occupy successive memory slots?

If I define

vector<double> v;
does this vector occupy successive memory slots? If it occupies successive memory slots, what would happen if I add some new element to this vector while there is not enough memory slots right after the last element?

Answer Source


The elements are stored contiguously, which means that elements can be accessed not only through iterators, but also using offsets on regular pointers to elements.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download