Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > array of vector!

Reply
Thread Tools

array of vector!

 
 
TF
Guest
Posts: n/a
 
      07-23-2003
I have a fixed array of vectors like:

vector<string> a_vStr[10];

Then I grow each vector item and use it later. Everything works fine
but I am curious about following potential problem.

When we grow a vector it may copy all of its elements to different
memory location to accomodate the new vector size. Is it possible that
at some point an element of fixed array e.g. a_vStr[5] gets invalid or
does not point to the vector it was pointing to at begining?
 
Reply With Quote
 
 
 
 
Peter van Merkerk
Guest
Posts: n/a
 
      07-23-2003
"TF" <> wrote in message
news: om...
> I have a fixed array of vectors like:
>
> vector<string> a_vStr[10];
>
> Then I grow each vector item and use it later. Everything works fine
> but I am curious about following potential problem.
>
> When we grow a vector it may copy all of its elements to different
> memory location to accomodate the new vector size. Is it possible that
> at some point an element of fixed array e.g. a_vStr[5] gets invalid or
> does not point to the vector it was pointing to at begining?


No, because the size of the vector object itself remains unchanged
during run-time. The size of the vector object itself is independant of
the number of elements it holds during run-time. Like any other class,
the size of the vector object is determined during compile time and
therefore is fixed. Modifying one vector in the a_vStr[] array will not
affect the other vectors in that array

For vector objects there are two blocks of memory needed; one to store
the vector object itself (in your example that would be a element in the
a_vStr[] array), and another to hold the elements of the vector (those
will be stored outside the a_vStr[] array). Certain operations on a
vector may cause the elements stored in the vector to be moved in
memory, however the memory location of the vector object itself will not
change. In other words iterators or pointers to elements in a vector may
become invalid if the vector changes, but the vectors in the a_vStr
array will remain valid.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM
How to combine 2 int Array into ONE int Array ? S300 Java 4 08-19-2003 07:04 PM
hashed array in array need the keys... and length Daniel Perl 1 08-14-2003 06:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57