how to fix stack overflow

Hi

I have big matrices like 600*600 and larger in my code. I'm trying to estimate a parameter and the solution is iterative. so I have to do lots of matrix multiplication in my code. When the size of my matrices become bigger than 600*600, I GET an stack overflow error. I don't know how I have to solve this issue. I read somewhere that I have to use NEW to allocate array on heap. Does anyone know how I have to do this? Or any other solution for my problem.
If you need to see my code, I can email it to you.

Thanks
1
2
3
4
5
6
const unsigned int vSize = 600*600;
// instead of this
int iVec[vSize];
// do this
int *iVec = new int[vSize];
// and remember to delete [] iVec when you're done with it 
This should have the info you need:
http://cplusplus.com/doc/tutorial/dynamic/
Thanks for your reply.
I didn't used something like:
int iVec[vSize];
I always use malloc to define and allocate memory for my variable.
I'm a little confused. for example, if I defined and initialized a matrix like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
float **m;
  
   m = (float**) malloc((nrow+1)*sizeof(float*));
   m[0] = (float *)malloc((nrow*ncol+1)*sizeof(float));

  for(int ii=1; ii<nrow; ii++)
       {
            m[ii] = m[0] + ii*ncol;
       }
  for(int ii=0; ii<nrow; ii++)
  {
        for(int j=0; j<ncol; j++)
      {
        m[ii][j] = 0;
      }
}


how I have to change it to solve my problem.

Topic archived. No new replies allowed.