我想保留空間向量的向量的載體,但它不工作,並拋出以下錯誤:分配內存爲載體
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