Questions tagged [bad-alloc]

std::bad_alloc is the type of exception thrown when memory allocation fails in a C++ program

In C++ when operator new or std::allocator cannot allocate memory an exception of type std::bad_alloc will be thrown.

265 questions
1
vote
0 answers

Google protocol buffer always throw bad allocation exception

I'm newbie in google protocol buffer. And now I have a issue as below: I have created a simple message in testMessage.proto file: option optimize_for = SPEED; message TestMessage { optional string foo = 1; optional string bar = 2; } Then…
Trung Nguyen
  • 818
  • 2
  • 10
  • 17
1
vote
4 answers

No output while doing try catch in c++

I am trying to catch bad allocation error. When input length will be in order of 10000000000000000000000 or something, then bad allocation error should come. I don't know why its not being caught. Any help will be appreciated! # include #…
1
vote
1 answer

What are some good practices to help prevent std::bad_alloc in unordered_maps and vectors?

So I'm making a program that reads through 10,000 lines of code. I have an unordered_map of vectors, and each line adds data to that unordered_map (either in the form of a new key or adding additional data to one of the vectors). For each line, I'm…
1
vote
0 answers

C++ code exiting randomly after reading different number of lines in a file

I am trying to read mesh data from a fluent mesh file. The code works perfectly till it reads node data. While reading cell data, it exits randomly by giving random negative number or what() std::bad_alloc. I am not able to understand the reason…
1
vote
0 answers

queue declaration causing std::bad_alloc

I wrote this code and it throws: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped) I get this error whenever I declare queue q(or deque q1) inside shortest_reach() function, and…
shiva
  • 2,535
  • 2
  • 18
  • 32
1
vote
1 answer

'std::bad_alloc' on remote server only (travis-ci)

I have this weird 'std::bad_alloc' thrown only during my test using travis-ci servers. I have tested my code on several machines, with the same compilers options, and I don't call any external library (only standard c++11). ./convexhull…
azzaare
  • 11
  • 2
1
vote
1 answer

bad_alloc on vector.push() and vector.reserve()

I am trying to build a vector of GLfloat of size 772538368. While doing push_back() I am getting bad_alloc error. After checking this question, I tried to reserve() memory for the vector. However, now I am getting the same error on the attempt of…
Sayan Pal
  • 4,768
  • 5
  • 43
  • 82
1
vote
1 answer

std::vector bad_alloc without using push_back

I have to read in very large text files in Qt, up to 3 GB, and store them as a collection of lines. (To work with them later) I know the lines have a very similar size, so i calculate a possible amount of lines and resize the vector before reading…
hisMajesty
  • 11
  • 4
1
vote
2 answers

Programm terminating "std::bad_alloc" after some time

I wrapped my mind around this, yet can not find the error. Could anyone help me where I did bad programming. One boost::thread receives strings over a socket, splits them to vector and sorts them into the right variable inside shared class.…
droid192
  • 2,011
  • 26
  • 43
1
vote
0 answers

Boost::asio return std::bad_alloc

I tried to run my basic server on 3 different computer (2 on windows and 1 linux) and only my computer fail to run correctly the server. After one or two request, boost asio throw a std::bad_alloc. I checked with Valgrind: no leaks. Linux run my…
The Bluff
  • 91
  • 9
1
vote
1 answer

bad_alloc exception with vectors in c++

I'm not very expert in programming with c++ so my question may appear a bit stupid, but I can't understand what I'm doing wrong. I want to allocate a vector with the instruction vector myvec(rowotot * coltot) in order to represent a…
Cate
  • 11
  • 1
  • 4
1
vote
1 answer

Unable to run Android emulator (BadAlloc (insufficient resources for operation))

I am unable to run my android emulator. When I run the app I get the following in the console: /home/thom/Programs/android-sdk-linux/tools/emulator -avd Nexus_5_API_23 -netspeed full -netdelay none X Error of failed request: BadAlloc (insufficient…
Thom Thom Thom
  • 1,279
  • 1
  • 11
  • 21
1
vote
1 answer

Program giving bad alloc error

I have writen a program on generating a square filled matrix filled with element from 1 to n^2 in spiral order.It is giving a bad alloc error. The error message is something like this terminate called after throwing an instance of 'std::bad_alloc' …
1
vote
4 answers

Handling exception in function returning std::string

How to handle std::bad_alloc exception in this function: std::string GetString() { std::string str; return str; } Since any stl constructor can throw bad_alloc, we've to do like this: std::string GetString() { try { …
Atul
  • 3,778
  • 5
  • 47
  • 87
1
vote
2 answers

C++ Out of Memory Exception Test

I have written a program for a double-ended queue using an array in C++. One of the requirements of the assignment is to handle exceptions. One of the exceptions we are supposed to check for is the out of memory exception. Since it is a…
GusGus
  • 230
  • 6
  • 16