导致C崩溃的数组大小

我正在努力在C中创建大量的结构。我需要数组来容纳超过100万个结构实例。 但是当arrays大小超过几十万时,程序崩溃了。 它运行良好的第一位然后它崩溃。 我正在运行带有6 GB RAM的Windows 7。

这个问题的根本原因是什么? 以下是代码

struct Job { unsigned long id; unsigned int num_preds; unsigned int resources; unsigned int* pred_array; }; int main() { //Counter and loop variables (Do not use for any other purpose) unsigned int i,j,k,count; unsigned long height,num_jobs; // This is our input section height = 1000; //Calculate the number of jobs num_jobs = (height+1)*height*0.5; printf("%d \n",num_jobs); struct Job jobs[num_jobs]; return 0; } 

堆栈的大小有限。 尝试使用malloc在堆上分配大型数组。