January 17th, 2003, 11:29 AM
STL vector and continuous memory :confused:
as far as I understand (from B. Strousrup's book) - std::vector can resize itsefl in the same manner as if one would use the C standard lib. function realloc() on C array allocated on the heap.
is it safe to assume STL vector allocates and re-allocates its elements continuously in memory so that there is no gaps between them?
thanks in advance !
July 10th, 2003, 09:08 PM
Yes, the vector is guaranteed to store its elements in a contiguous block of memory, like a regular C-language array. string and deque also have this guarantee.
You can read more about it in Scott Meyers' excellent book, "Effective STL."