[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

what(): St9bad_alloc error . Abort

hi,

i am using push_back and  i got the above error.

could anyone pls pls help. tks
0
zizi21
Asked:
zizi21
  • 4
  • 4
1 Solution
 
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
Infinity08Commented:
And : are you sure that it's the push_back that generates the exception ?
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now