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 = newdouble[nwk+1];
but I am getting this error:
terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_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?
It's hard to tell without knowing the size of nwk.
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.
@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.