在我的项目中,有 100 万个输入,我应该将搜索/排序算法与不同数量的输入进行比较,直到达到 100 万个输入。我想用数据一起进行内存分配和初始化,但我意识到这是不可能的。所以我决定这样做;
double temp1, temp2, temp3; //Each line has three numbers
int i;
Person *list[N]; //Here, stackoverflow occurs, for example N=500000
for(i=0; i<N; i++){
file >> temp1 >> temp2 >> temp3;
list[i] = new Person(temp1, temp2, temp3); //I wanted to initialize with data
} //but if I wrote "new Person[N]"
//stackoverflow doesn't occur
但是有一个巨大的数字溢出,例如N = 500000。那么,有没有将这两者结合起来的方法?(没有溢出和数据初始化)
其次,这两个代码之间有什么区别;
Person *list[N];
for(i=0; i<N; i++){
list[i] = new Person();
}
Person *list = new list[N];