Sep 7, 2012 at 6:16pm UTC
Hi, I'm having an issue with an allocation error. I have a very large integer nwk that is an unsigned long.
I want to dynamically allocate an array of length nwk
double *A = new double[nwk+1];
but I am getting this error:
terminate called after throwing an instance of 'std::bad_alloc'
I assume this is because I'm trying to allocate a really long array. But I need all that space to solve this large problem. Is there some way to fix this?
Sep 7, 2012 at 6:31pm UTC
It's hard to tell without knowing the size of .
If I remember correctly, double's are 8 bytes large, so multiply that by nwk and you'll have an idea of how much memory you're trying to allocate.
Perhaps an STL container (vector, deque,...) would also be a safer way to implement such large storage.
All the best,
Sep 7, 2012 at 8:18pm UTC
ne555: No, (s)he wants to allocate a large block of memory for kicks. If they need the memory, so be it; there's no need to question their requirements. Besides, we don't even know what the program is or even does.
Sep 7, 2012 at 8:42pm UTC
That's exactly what I'm trying to know (in order to provide an useful answer)
If you run out of memory then download some RAM, xP