Re: Max size of data in C++ prog?
On Sun, Dec 19, 2004 at 11:31:13AM -0500, Marc Shapiro wrote:
> On Sun, 19 Dec 2004 12:32:12 +1100 Sam Watkins <swatkins@fastmail.fm> wrote:
> >
> >there are two different data segments for a C or C++ program,
> >the stack and the heap.
> >
...
> >
> > vector<int> v;
> > int i;
> > for (i=0; i<10000000; ++i)
> > v.push_back(i);
>
> Vectors are single dimensional, I believe, so they wont work in this
> case, but I will remember them for the future
>
You can get multidimensional arrays using STL vector like this:
typedef vector<int> Vint;
typedef vector<Vint> VVint;
typedef vector<VVint> VVVint;
with these in an include file, you can use
Vint v;
instead of the definition above, and
VVint v;
if you want v to be a 2d array.
Strong type checking warns you of any inattention to detail in your
usage.
I use STL vectors of int, of short, and of double extensively in my
simulation work. I like being able to use i<v.size() as the
termination condition in a for statement. (It works once the vector
has been properly initialized through allocating statements such as
v.push_back(i), as is suggested, above.
If you look into STL and find it attractive, I heartily recommend
The C++ Standard Library, A Tutorial and Reference, by N. M. Josuttis.
It gives both good overview and detailed syntax and more.
--
Paul E Condon
pecondon@mesanetworks.net
Reply to: