I need a program to solve a PDE numerically. I first wrote a smaller program which worked very well. After extending the program I receive now exception which says "std::bad_alloc".
The offending line comes from a function lu_solver() I wrote. The line should allocate memory dynamically. I read a bit about std::bad_alloc. It should be thrown if memory cannot be allocated. But this function worked perfectly well in the first program before. The only change is that the function lu_solver() was called upon directly before and it is called by another function now. I attach only a part of the code because the whole program is too long.
Unfortunately, that doesn't really help to answer the problem.
How is your program using the memory? Are you trying to allocate some huge Dim at some point? (Or negative? Or Zero?) Are you trying to use lu_solver() a whole lot of times? Etc.
You can catch() the error by wrapping the new statement in a try..catch block...
I am not really aware how I am using the memory. The int Dim is always positive and of the order of several thousand. But lu_solver() is called repeatedly, about ten thousand times. I thought if I deleted y every time after using there would be no memory problem.