2013-05-06 55 views
-1

我宣称HTwoDimArray函数为2D动态数组。当线(标记为**)执行时,编译器显示误差:

Access violation writing location 0x61d1e5bc.访问冲突写入位置0x61d1e5bc

小海伦& LENB值(如250),没有任何问题!

int lenA=100030; 
int lenB=100030; 
int **H; 

int TwoDimArray(int ***x,int nRow,int nCol) 
{ 
    int i; 
    *x=(int **)malloc(nRow*sizeof(int *)); 
    if(*x==NULL) 
     return 1; 
    (*x)[0]=(int *)malloc(nCol*nRow*sizeof(int)); 
    if((*x)[0]==NULL) 
     return 2; 
    for(i=1;i<nRow;i++) 
     (*x)[i]=(*x)[i-1]+nCol; 
    return 0; 
} 

    TwoDimArray(&H, lenB, lenA); 

    for(int j=0;j<lenA;j++){ 
     H[0][j]=0; 
    } 

** for(int i=0;i<lenB;i++){ 
     H[i][0]=0; 
} 
+3

**编译器**显示错误? – trojanfoe 2013-05-06 18:49:47

+0

'H'在哪里?给我们看一看。 – 2013-05-06 18:50:28

+1

这不是C++ – yngccc 2013-05-06 18:51:14

回答

6

100030 X 100030阵列的32位整数需要RAM 40GB。你的程序是否可以访问这么多的内存?

很有可能第二个malloc失败。但是,您的代码无视失败并继续进行。

+0

你说得对。谢谢。 – 2013-05-06 19:08:44