Hi,

I wish to know that the cause of the following error when i run the program :
a) Is memory leak in the program
B) The system on which i am running the program has insufficient memory.

terminate called after throwing an instance of 'St9bad_alloc'
  what():  St9bad_alloc

Thanks

Recommended Answers

All 3 Replies

A bad_alloc exception is thrown when dynamic memory allocation has failed, I think this is often the case when your system has not enough memory, or are you allocating to much memory ?

A memory leak could be, but me eyesight is not good enough to see your program's source code from here :P

A bad_alloc exception is thrown when dynamic memory allocation has failed, I think this is often the case when your system has not enough memory, or are you allocating to much memory ?

A memory leak could be, but me eyesight is not good enough to see your program's source code from here :P

My code has 3000 lines and i do not know in which function the error is..so i did not paste the code.

3000 lines? are they all in main()? If that is the case that is your 1st problem. 3000 lines or 30,000 lines want matter if you break the code down.

Get into the habit of writing smaller methods. I usually try to keep my methods as simple and small as possible. 1 operation per method. Usually for me an average method is around 15 -20 lines of code. Some are of course more. But generally when you do big project break your project down to smaller "programs" and code those "programs" and finally integrate them, which usually doesn't take as much time as trying to figure out an error in a 3000 line code.

As for this error. How much memory does your machine have? If you think lack of memory is the issue then try closing some background programs. When you run program check how much memory is being used by your program.

I think its not a memory leak but you are trying to access a memory location that doesn't exist. Just a thought.

If you can figure out where the error occur and post someone here will be able to help.

Go to where you create the vector and then use the vector + then the error line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.