访问冲突写入位置 0x00000000。当将数组的大小时增加到 calloc

Access violation writing location 0x00000000. When increase size of array to calloc

我尝试使用 255 调用 2d 数组和边缘单元格的初始值,它工作正常但是当我尝试将数组的维度设置为超过 12000*12000 时,VS2010 显示访问冲突写入位置 0x00000000

我的calloc二维数组函数

int **calloc_2d_int(int Rows, int Cols) {
      int *data = (int *)calloc(Rows*Cols,sizeof(int));
      int **array= (int **)calloc(Rows,sizeof(int*));
      for (int i=0; i<Rows; i++)
           array[i] = &(data[Cols*i]);
      return array;
}

主要功能

int main(int argc, char* argv[]){   

int i,j;

/*convert string to int*/
int row    = atoi(argv[1]);
int column      = atoi(argv[2]); 
int T           = atoi(argv[3]); 

int** s[2];

s[0] = calloc_2d_int(row,column);
s[1] = calloc_2d_int(row,column); 
for(i=0 ; i<row ; i++){
    s[0][i][0]        = 255;   //error at this line 
    s[1][i][0]        = 255;
    s[0][i][column-1] = 255;
    s[1][i][column-1] = 255;
}

for(i=0 ; i<column ; i++){
    s[0][0][i] = 255;
    s[1][0][i] = 255;
    s[0][row-1][i] = 255;
    s[1][row-1][i] = 255;

}
}

谢谢

Access violation writing location 0x00000000

这意味着您正在尝试在 NULL 指针上写入。所以 calloc 返回 NULL.

正如您在 calloc manpage 上看到的那样,它 returns NULL 出错,这可能是一个太大的内存请求。
根据您的系统,13000 * 13000 (169 000 000) 可能太大了。

始终检查 malloccallocrealloc returns 是否有错误。