So I'm making a program that reads through 10,000 lines of code. I have an unordered_map of vectors, and each line adds data to that unordered_map (either in the form of a new key or adding additional data to one of the vectors).
For each line, I'm storing data using emplace. For example, I'll have a
vector <int> temp;
that I store data in using
temp.push_back(someInt);
and then store that vector in my unordered_map with
uList.emplace(someKey, temp);
temp.clear();
or I add data to one of the map vectors using
uList[i].push_back(someInt);
This happens multiple times per line, then I move on to the next line and do it all over again, 10,000 times.
The error I get is
"terminate called after throwing an instance of 'std::bad_alloc'"
I'm assuming it's because of problems allocating memory with my unordered_map or the vector I have.
My question is: Can an unordered_map have issues allocating memory if I use .emplace() too many times, and are there any common practices used to prevent bad allocation with vectors or unordered maps?
Any advice is appreciated, even calling me out on me saying something stupid would help!