stack overflow just because of a double array[500][500]?

J

James

Hi,

I am using Visual C++ 6.0. I got a "stack overflow" error message when
running the program because of a "double array[500][500]". I have a
computer with 1GB memory. Can I extend the memory for the program
running? How?

Looking forward to hearing from you!

Regards,

James
 
J

John Harrison

James said:
Hi,

I am using Visual C++ 6.0. I got a "stack overflow" error message when
running the program because of a "double array[500][500]". I have a
computer with 1GB memory. Can I extend the memory for the program
running? How?

Possibly but how big the stack is something that your compiler specifies not
the C++ language. Ask in a compiler specific group for an ansewr to this
question.

But really you should use dynamic allocation, any of the methods I suggested
in response to your last post would be prefereable to trying to declare such
a huge array on the stack.

For instance

#include <vector>

std::vector<std::vector<double> > array(500);
for (int i = 0; i < 500; ++i)
array.resize(500);

is a simple way to give you a 500 by 500 2D array without blowing your
stack.

john
 
J

Jacek Dziedzic

James said:
Hi,

I am using Visual C++ 6.0. I got a "stack overflow" error message when
running the program because of a "double array[500][500]". I have a
computer with 1GB memory. Can I extend the memory for the program
running? How?

It's not the "memory for the program running" it's the stack size
that is too small. <OT> You may adjust it via some compiler options,
I believe. </OT>.

Better than that, don't have this 4MB array allocated on stack
(which happens, for instance, if it's a local variable inside a
function) -- try going for dynamical allocation, using 'new' for
example. See your book's index for "new", "dynamical allocation",
and also the C++ FAQ-lite for how to handle two-dimensional
arrays using 'new'.

You might also consider using a
std::vector< std::vector <double> >
for storing your doubles.

HTH,
- J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top