Why does my program occasionally segfault when out of memory rather than throwing std::bad_alloc?

Posted by Bradford Larsen on Stack Overflow See other posts from Stack Overflow or by Bradford Larsen
Published on 2010-04-02T16:07:41Z Indexed on 2010/04/02 16:43 UTC
Read the original article Hit count: 261

Filed under:
|
|

I have a program that implements several heuristic search algorithms and several domains, designed to experimentally evaluate the various algorithms. The program is written in C++, built using the GNU toolchain, and run on a 64-bit Ubuntu system. When I run my experiments, I use bash's ulimit command to limit the amount of virtual memory the process can use, so that my test system does not start swapping.

Certain algorithm/test instance combinations hit the memory limit I have defined. Most of the time, the program throws an std::bad_alloc exception, which is printed by the default handler, at which point the program terminates. Occasionally, rather than this happening, the program simply segfaults.

Why does my program occasionally segfault when out of memory, rather than reporting an unhandled std::bad_alloc and terminating?

© Stack Overflow or respective owner

Related posts about c++

Related posts about bad-alloc