“std::bad_alloc”: am I using too much memory?
(moving/expanding from the comments) Since you are allocating a new array every time without deallocating it, you have a massive memory leak, i.e. you continue to ask memory to the system without ever giving it back. Eventually the space on the heap finishes, and at the next allocation all you get is a std::bad_alloc exception. … Read more