• C

what(): St9bad_alloc error . Abort

hi,

i am using push_back and  i got the above error.

could anyone pls pls help. tks
zizi21Asked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
And : are you sure that it's the push_back that generates the exception ?
0
 
Infinity08Commented:
bad_alloc indicates that a memory allocation failed.

push_back is used for some standard C++ STL containers, which internally perform memory allocations.

So, in summary : you have probably grown the container to such a big size that the next push_back caused the container's size to become too big.
0
 
Infinity08Commented:
(btw : that would be a C++ question, not a C question ;) )
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
zizi21Author Commented:
but the current size is 1.

sam.arr.push_back(n);
also, after using it, i erase the elements to ensure that lots of mem is not used.
sam.arr.erase(sam.arr.begin(),sam.arr.end());

sam is an array but i had to remove the [ ] brackets as i couldn't submit the question.
0
 
zizi21Author Commented:
since i am using push_back, no space was reserved as it seemed unnecessary.
0
 
Infinity08Commented:
Can you show the exact code you are using ?

Or if that's not possible, can you post a representative sample that exhibits the same behavior ?
0
 
zizi21Author Commented:
okay, i would produce a sample that generates the exception and post the code here.
0
 
zizi21Author Commented:
thanks a lot. it was another part of the code. thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.