Quote Originally Posted by FillYourBrain View Post
yeah, sure. Resize the thing, get the pointer to the first element, and access the nth element. Guaranteed that its not moved, resized, smaller than n at that time?
If you have given the vector a size from the start (or resized it later, or taken it's size after a number of "push_back" operations), then you can be guaranteed that elements are going to be there, yes. You can, however, not rely on element 7 being there if you haven't in some way made the vector at least 7 elements long.

And as long as you do not resize the vector, a ppinter to any element will remain valid forever. Obviously, any resiziing (either extending or shortening) may invalidate a pointer holding the address of the vector content.

And vectors are GUARANTEED to be implemented in one contiguous chunk of memory. [obviously, we are talking about the virtual address, in the physical memory, that may be discontiguous, but unless you are working inside a driver, you don't need to know that].

--
Mats