Pae*_*ula 2 c size malloc global-variables limit
我如何解决Visual Studio Visual C#C2148错误?以下是产生错误的代码:
#define ACOUNT 2000
#define BCOUNT 9000
#define CCOUNT 195
struct s_ptx {
int pvCount[ACOUNT][BCOUNT][CCOUNT];
} ;
Run Code Online (Sandbox Code Playgroud)
这将生成VStudio 2010 Visual C(在64位以下编译)错误#C2148:错误C2148:数组的总大小不得超过0x7fffffff字节
我知道我可以动态分配pvCount 3d数组,但后来我必须做一个zillion alloc和free.我有192 gig的内存,所以我试图找到一个允许这种大小的编译器开关或选项.
编辑:我在试图简化事情时遗漏的复杂问题是ptx是一个指针,在运行时用作结构数组:
ptx *Ptx = (ptx *) calloc(10, sizeof(ptx));
for (int i = 0; i < 10; ++i)
{
Ptx->pv = (int (*)[BCOUNT][CCOUNT] ) malloc( (unsigned long) ACOUNT * BCOUNT *CCOUNT * sizeof(int));
}
for (int jav = 0; jav < 10; ++jav)
for (int j = 0; j < ACOUNT; ++j)
for (int k = 0; k < BCOUNT; ++k)
for (int m = 0; m < CCOUNT; ++m)
Ptx[jav].pv[j][k][m] = j + k + m;
Run Code Online (Sandbox Code Playgroud)
因此,当我运行代码时,我得到访问冲突错误,大概是因为通过动态分配我不再能够使用:Ptx [jav] .pv [j] [k] [m]
你不需要zillion mallocs.只是:
int (*arr)[BCOUNT][CCOUNT]=malloc((size_t)ACOUNT*BCOUNT*CCOUNT*sizeof int);
Run Code Online (Sandbox Code Playgroud)
编辑:转换size_t为必要,不溢出int.