473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

array of vector!

TF
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?
Jul 19 '05 #1
1 19585
"TF" <fa****@coned.com> wrote in message
news:ae**************************@posting.google.c 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.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: BCC | last post by:
Ive been googling and reading through my books but I haven't figured out a solution (much less an elegant one) to create a multidimensional array with a runtime determined number of dimensions. I...
49
by: vfunc | last post by:
If I have a large array 10,000+ elements then how do I reserve memory for this ? Currently I get a segmentation fault. Dynamic reservation is good, but allowing a chunk for the program is an...
20
by: Martin Jørgensen | last post by:
Hi, I'm reading a number of double values from a file. It's a 2D-array: 1 2 3 4 5 6 7 ------------- 1 3.2 2 0 2.1 3 9.3 4
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
9
by: JoeC | last post by:
I am crating a new version of my map game and my map will be a 2d array. I had problems trying to create a 2d array dynamically, in fact C++ won't let me do it. My question is how to create the...
3
by: Matthias Pospiech | last post by:
I have an 2D vector array, but a function that can calculate only with 1D arrays. Now I need to pass every row of the 2D array to that function. So how can I pass a part (row or column) of a 2D...
7
by: hlg | last post by:
I have a question, which must surely have occurred to many programmers since STL first appeared, and yet I have found no reference to it anywhere, suggesting the problem is insoluble. Nevertheless,...
6
by: remlostime | last post by:
now, i write some code code1: int a; int main(){} code2: vector<inta(10000000); int main(){} after using g++ compile, and run it, code1 is broken, but code2 runs
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.