我想保留空间向量的向量的载体,但它不工作,并抛出以下错误:分配内存为载体
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
每次我用一个足够大的数。的我有一个最小的版本下面是:
#include <vector>
#include <iostream>
using namespace std;
int main(){
int base;
cout << "Enter Base: ";
cin >> base;
int dimension;
cout << "Enter Dimension: ";
cin >> dimension;
int perms = 1;
for(int i=0; i<dimension; i++){
perms *= base;
} // This gets the number of permutations with repetition
int length;
cout << "Enter Length: ";
cin >> length;
float structSize = 1.0;
for(float i=0.0; i<length; i++){
structSize *= perms-i;
structSize /= (i+1.0);
} // This gets the number of combinations
vector< vector< vector<double> > > allStructs;
allStructs.reserve(structSize);
return 0;
}
应该为大structSizes工作,但在基部= 3,尺寸= 4,长度= 6这使得structSize = 324540216失败。这有可能工作吗?
是的,这是可能的 - 增加更多的内存到你的电脑 – Slava
你有没有做这个数字需要多少内存? –
你真的要存储每个结果吗?你不能只是迭代结果吗? – Jarod42