What are the reasons a bad_alloc would be thrown when I resize a vector? I know it means that new memory could not be allocated, but what can I do to prevent that from happening?
To be more specific, I have a class-member vector of vectors that is initialized to size 0x0. I resize it to 22x0, then begin incrementally resizing it to 22x2, like this:
at i=2, a bad_alloc is thrown at resize. This happens on both my desktop and laptop. It only happens when other class-members (which are vectors of vectors) are resized before this. If I don't resize the other vector of vectors, then everything is fine.
I've amateurishly tried using vector::reserve, but the same problem arises.
Any ideas?
To be more specific, I have a class-member vector of vectors that is initialized to size 0x0. I resize it to 22x0, then begin incrementally resizing it to 22x2, like this:
Code:
Steps = 20;
theExtendedTree.resize(Steps+2);
theExtendedTree[0].resize(1);
theExtendedTree[0][0].first = Spot;
for (unsigned long i=1; i <=Steps + 1; i++)
{
theExtendedTree[i].resize(2);
theExtendedTree[i][0].first = theExtendedTree[i-1][0].first * upFactor;
if ( i >1)
theExtendedTree[i][1].first = theExtendedTree[i-1][1].first * downFactor;
else if (i==1)
theExtendedTree[i][1].first = theExtendedTree[0][0].first * downFactor;
}
I've amateurishly tried using vector::reserve, but the same problem arises.
Any ideas?