Program terminating with std::bad_alloc
I am running a C++ program, which dies with std::bad_alloc at arbitrary
points, which depend on the input specified. Here are some
observations/points about the program:
for shorter runs (the running time depends on the input), the program
completes normally. The problem comes only for larger runs.
the program does not have any detectable memory leaks. This was checked
with Valgrind/Memcheck for smaller runs. Moreover, my entire code does not
have any pointers (all dynamic allocations are done by the libraries,
e.g., in std::vector and std::string; it is the allocation inside these
library classes which fails), so memory leaks are extremely unlikely.
several objects are allocated in loops and then moved to containers.
Several of these objects are intended to be alive until almost the end of
the program.
I suspected heap fragmentation could be an issue (see C++ program dies
with std::bad_alloc, BUT valgrind reports no memory leaks) but I am on a
64-bit system with a 64-bit compiler (specifically Linux with g++) and
Heap fragmentation in 64 bit land leads me to believe heap fragmentation
cannot be an issue on 64-bit systems.
Is there anything else I should try? Any particular tools that could help?
Any other suggestions?
UPDATE: It finally turned out that the virtual memory had been limited
through ulimit -v earlier. I forgot about this later, and hence had memory
exhaustion. Setting it back to unlimited fixed the problem.
No comments:
Post a Comment