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
1 answer

std::bad_alloc: determining the buffer size in Eigen

I use Eigen's matrix format to read a previously acquired multi-dimensional data: Eigen::Matrix dummyData; and later on after knowing my data size: dummyData.resize(PackSize, 12); PackSize could be in order…
QuestionMark
  • 412
  • 1
  • 4
  • 16
1
vote
2 answers

What to do if I get std::bad_alloc?

Creates 2d array of organism class pointers: try{ world = new Organism**[worldSizeX]; for (int x = 0; x < worldSizeX; x++){ world[x] = new Organism*[worldSizeY]; // INITATES world ARRAY for (int y = 0; y <…
Cirvis
  • 382
  • 1
  • 4
  • 15
1
vote
1 answer

How to solve bad alloc() runtime error?

I am getting the std::bad alloc() exception in a code I have written. According to other answers on SO, I should free the dynamically allocated memory but the exception remains. Any leads on how I can solve it? I am attaching the function where the…
TheBlueNotebook
  • 1,204
  • 3
  • 15
  • 35
1
vote
2 answers

C++ bad_alloc thrown in a constructor

When a bad_alloc exception is thrown in a constructor, in which multiple objects are created, what must be done to clean up the memory. Ex. class Object { private: A * a; B * b; public: Object() { a= new A(); b=…
Rafa
  • 1,151
  • 9
  • 17
1
vote
4 answers

Bad_alloc exception when using new for a struct c++

I am writing a query processor which allocates large amounts of memory and tries to find matching documents. Whenever I find a match, I create a structure to hold two variables describing the document and add it to a priority queue. Since there is…
bsg
  • 825
  • 2
  • 14
  • 34
1
vote
1 answer

Strange std::bad_alloc in an already-created vector

I'm running on a std::bad_alloc error. As far as I know and as I've seen researching on StackOverflow this can be caused by a lack of the necessary memory to perform an action or because there's some kind of corrupted datastructure (as explained…
JuanGM
  • 25
  • 9
1
vote
2 answers

std::bad_alloc when allocating a new vector - what can I do

I have a Problem. I have a huge c++-project that I change at a few points to meet my requirements. I load more data than expected and at some point in this program there is a new vector allocated with the size of the number of data multiplied by…
smaica
  • 723
  • 2
  • 11
  • 26
1
vote
3 answers

Program crashes - bad_alloc when creating new char array

I have a C++ function that splits a char array into multiple char arrays when it encounters a delimiter. For some reason, when saving the third split array the program just crashes and sometimes returns an std::bad_alloc exception. char **…
Fabis
  • 1,932
  • 2
  • 20
  • 37
1
vote
2 answers

Unhandled exception bad_alloc at memory location

In c++ a bad_alloc happen while assigning memory, or at least that was what I understood, but now I get this error while reading memory from an array. I create the array: int * possible = new int[ suma ]; and then i got two for cycles, where I…
Toxa Kniotee
  • 55
  • 1
  • 7
1
vote
0 answers

std::bad_alloc on retrieval from vector

(I've never asked a question here before so please excuse me if I don't follow proper etiquette) I'm working on a scene graph for use in a GLWidget, and I'm running into a weird case of bad_alloc. Each node (called a graphNode) in my scene graph…
1
vote
0 answers

gdb "Junk at end of arguments." when trying "catch throw std::bad_aloc"

I've been trying to debug an instance of std::bad_alloc in gdb. In gdb 7.4.1 and 7.5.91 I tried (gdb) catch throw std::bad_alloc Junk at end of arguments. I've tried wrapping std::bad_alloc in single and double quotes, without success. Is there a…
invisiblerhino
  • 840
  • 1
  • 10
  • 18
1
vote
2 answers

std::map::begin() returns an iterator with garbage

typedef unsigned long Count; typedef float Weight; typedef std::map StringToCountMap; typedef std::map StringToWeightMap; typedef std::map UnsignedToStringToCountMap; typedef…
Osuvaldo
  • 274
  • 3
  • 10
1
vote
1 answer

C++ bad_alloc caused by new?

[Fore note: I have read the existing threads in StackOverflow. None seemed to be on my question] I am looking into the Quake 2 MD2 format. I seem to be getting a bad allocation after new'ing a pointer-array. However, if I do some horrible pointer…
1
vote
1 answer

C++ Exception: bad_alloc at memory location

Unhandled exception at at 0x7650C41F in binary.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003EEE00. First-chance exception at 0x77983AB3 (ntdll.dll) in binary.exe: 0xC0000005: Access violation reading location…
Ryan
  • 957
  • 5
  • 16
  • 34
1
vote
1 answer

C++ Populating deque bad allocation

I'm trying to make a huge collection of random numbers to do algorithm analysis. Then I came across this problem that I can't explain. Consider the following code: #include #include #include typedef unsigned long long…
hezzze
  • 31
  • 3