std::bad_alloc issue

Hello,
I am working on a program which creates a large pointer array of numbers and then performs several iterations of operations in them.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int * u = new int[N];
double * nu = new double[N];
int * nud = new int[N];
for (int i=0;i<M;i++){

     for (int i=0;i<N;i++){
	u[i]=0;
	nu[i]=0;
	nud[i]=0;
     }

     (perform some operations on nu and nud, increment a counter)


}


If M is small enough then there are no problems in the program. However once M is large enough I get the "unhanded exception":

std::bad_alloc at memory location 0x0026f728..

Since I am just reusing the same arrays, and since I am able to make it through more than one iteration, I didn't think it could be a memory issue. If it is, is there a way I can clear the data completely after each iteration?

Thanks!

Last edited on
Er, you are creating arrays of size N then looping through them up to NVN times. If NVN > N then you are in trouble.
Sorry, that was a typo. NVN should have been N.
Topic archived. No new replies allowed.