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

node.js creating bad_alloc

I'm attempting to start using node.js mainly for learning purposes, but I definitely see some potential that I will use in future projects. My problem - I'm using SSH on my Centos server and have gone through this tutorial:…
kdm5157
  • 61
  • 4
5
votes
1 answer

How to make the cartesian products of vectors, when the number of elements > 1000?

I have 1,2,...,n piece of vectors. Every vector has more than 10000 elements and I have to get the cartesian product of these vectors. I have a code, what's working, but only under 1000 elements and under 4 vector. I'd like to write the cartesian…
vizvezetek
  • 51
  • 4
5
votes
1 answer

What is the most common reason that "bad_alloc" is thrown?

Is there a more frequent error that is memory-related that throws bad_alloc? I understand that it means that memory-allocation has failed, but what is the most common mistake that leads to this in code?
Andy N.
  • 67
  • 1
  • 11
5
votes
1 answer

How to deal with bad_alloc in android java

I am using a ViewPager to show fragments. When i swipe it multiple times it gives following error: E/libc++abi: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc --------- beginning of crash A/libc: Fatal signal 6 (SIGABRT),…
Viks
  • 1,510
  • 4
  • 22
  • 50
5
votes
3 answers

New throws bad_alloc despite header not being defined?

How is it that a new expression in a program can throw a bad_alloc error despite there being no #include (since this error is defined in the header)? From 3.7.4. of N3337: The library provides default definitions for the global…
SergeantPenguin
  • 843
  • 7
  • 16
5
votes
1 answer

function doesn't throw bad_alloc exception

I'm trying to do an exercise form Stroustrup's C++PL4 book. The task is: Allocate so much memory using new that bad_alloc is thrown. Report how much memory was allocated and how much time it took. Do this twice: once not writing to the…
user4833046
5
votes
1 answer

`std::vector` throws a "bad allocation" exception when resized

I have the following code in a C++ dll, which I invoke through JNI: std::vector myVector; myVector.resize(10000000, 0); I get a "bad allocation" exception, even though the maximum size for the vector is supposedly larger than 10000000. What…
uahakan
  • 576
  • 1
  • 6
  • 23
5
votes
5 answers

C++ vector std::bad_alloc error

I'm trying to implement a suffix tree in c++ while adding nodes to my vector list, it throws std::bad_alloc after adding a third element into the tree. I don't know why it occurs after the third time, Could you help me resolving this bad_alloc error…
guillaume guerin
  • 357
  • 2
  • 6
  • 17
5
votes
4 answers

C++ memory allocation errors without use of new

I am having issues with my program throwing a large number of memory allocation exceptions and I am having a very hard time diagnosing the problem...I would post code, but my program is very large and I have proprietary information concerns, so I am…
brentf
  • 411
  • 2
  • 8
  • 14
5
votes
4 answers

std::map bad allocation error

I'm facing an issue with std::map. For unknown reasons sometimes insertions to map lead to a "bad allocation" exception. Below is the function which I use for inserting into the map. BOOL Add2WaitList(Object *newObj) { try { …
SairuS
  • 149
  • 1
  • 2
  • 11
4
votes
1 answer

Terminate called after throwing an instance of 'std::bad_alloc' from importing torch_geometric

I am writing in python and getting the error: "terminate called after throwing an instance of 'std::bad_alloc'. what(): std::bad_alloc. Aborted (core dumped)" After lots of debugging, I found out the source of the issue is: import…
4
votes
1 answer

Getting bad_array_new_length error when trying to load a text file into a dynamically allocated 2d array

So the issue I'm having with this code is that when I run it, I get the error: terminate called after throwing an instance of "std:bad_array_new_length" what(): std:: bad_array_new_length There are no errors otherwise and the code compiles just…
Spago
  • 69
  • 1
  • 1
  • 6
4
votes
2 answers

C++ creating huge vector

For a process I'm trying to run I need to have a std::vector of std::tuple. The test I'm doing right now should create a vector of 47,614,527,250 (around 47 billion) tuples but actually crashes right there on…
gioaudino
  • 573
  • 8
  • 23
4
votes
3 answers

bad_alloc when calling new on class Texture

This is the offending line: Texture *texture = new Texture (...); I receive from bad_alloc here: void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc) { // try to allocate size bytes void *p; while ((p = malloc(size))…
Rannath
  • 41
  • 1
4
votes
0 answers

How to discard old sinals in Qt?

I have three threads: My GUI, an UDPSocket and a worker thread. My UDPSocket is emitting a signal with the data to the worker thread. My problem is, that my worker thread is running slower than the UDPSocket emitting signals, so my programm…
honiahaka10
  • 772
  • 4
  • 9
  • 29
1
2
3
17 18