473,804 Members | 3,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 19609
"TF" <fa****@coned.c om> wrote in message
news:ae******** *************** ***@posting.goo gle.com...
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.merke rk(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
3209
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 also checked out the boost::multi_array.hpp, and Giovanni Bavistrelli's Array code. Neither of these seem to allow dynamic array dimensions. For example, the user selects a 2 dimensional array, I want to create: MyObject** array = new...
49
3181
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 acceptable alternative.
20
4653
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
7423
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 in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
9
2111
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 size of array I need at run time without using too much memory or going over the allotted size if I choose to use this object for a different game. One idea I have is to create space * spaces = new space; then have all my accessors just convert...
3
5447
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 vector array to a function as a pointer - the result shall be in the 2D array automatically. With C-Arrays A I know the solution by passing function(A + x*N);
7
3782
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, here it is: I wish to create an two-dimensional array of objects. On the one hand, it is useful to use STL containers for the rows and columns of the array. On the other, it would be nice to address the elements by the array element operator ...
6
1820
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
3771
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 when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of the 13 fields for that contact. when you double click the contact i want it to pop up and show all 13...
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.