-
February 22nd, 2013, 09:17 AM
#1
Problem with large pointer array
Hello,
I am working on a program which creates a large pointer array of numbers and then performs several iterations of operations in them.
Code:
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 a few iterations, 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!
-
February 22nd, 2013, 10:06 AM
#2
Re: Problem with large pointer array
You don't think bad_alloc is a memory issue? How big does N have to be to fail?
-
February 22nd, 2013, 10:23 AM
#3
Re: Problem with large pointer array
N is only around 4000. What bothers me is that I get bad_alloc after completing the first few iterations. If it was a memory problem I would expect it to fail during the first initialization. If M is set <7 it runs fine, but any greater and I get the unhandled exeption.
-
February 22nd, 2013, 10:26 AM
#4
Re: Problem with large pointer array
I don't see anything. Can you post complete code for a small program that reproduces the problem.
-
February 22nd, 2013, 03:40 PM
#5
Re: Problem with large pointer array
Originally Posted by goliath11
Since I am just reusing the same arrays, and since I am able to make it through a few iterations, I didn't think it could be a memory issue.
Well, let's see the complete program. A naked psuedo function with a call to new[] doesn't tell us anything. What if that missing code is corrupting the heap in some way?
For example, why are you using the same "i" in the nested loop as a counter in both loops? That in itself is a bug.
If it is, is there a way I can clear the data completely after each iteration?
Post a complete program. so that we know how to analyze the problem. So far, what you posted is incomplete, and it has a bug.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|