简体   繁体   English

分配给C代码的内存远远少于应该使用的内存

[英]Memory assigned to c code is much less than it is supposed to use

I am new to this forum... 我是这个论坛的新手...

I am working on a DSMC C code which is supposed to utilise 500MB of RAM space, as i have calculated considering sizeof(double)==8 and sizeof(int)==4 . 我正在研究应该利用500MB RAM空间的DSMC C代码,因为我已经考虑过sizeof(double)==8sizeof(int)==4 yet when i run the code the task manager of my windows8.1 shows only 172 MB of ram being used by the code.exe file.. why could this be happening... ? 但是当我运行代码时,我的Windows8.1的任务管理器显示code.exe文件仅使用172 MB的ram。为什么会这样...? I am using 10-15 really long multidimensional arrays like .. var_name[3][4050000] . 我正在使用10-15个非常长的多维数组,例如.. var_name[3][4050000] this concerns me as the result I need is also not as expected.. 这让我感到担忧,因为我需要的结果也不如预期。

All the variables are defined outside main() and are defined as static... 所有变量都在main()外部定义,并定义为静态...

#define MNC 202500
#define MNM 4050000
#define MNSC 16020000
...

static double PP[3][MNM],PV[3][MNM],CG[6][MNC],CT[MNC],CSS[9],CS[7][MNC],FDPCELL[MNC],FDPCELL1[4][4];
static int IR[MNM],ISCG[2][MNSC],IPL[MNM],ISC[MNSC],IC[2][MNC],DPCELL[MNC],DPCELL1[4][4],n;
static double NCOLM,NROW,NSLC,BMEJ;
static double TIME,FTMP,VFX,VFY,VFZ,VMP,TMPJ,FVJ,SELT,X,Y,Z;
...

int main()
{
    ...
    return 0;
}

it would be really great if anyone of you suggest me what could be wrong with such an unpredictable error... 如果你们中有人建议我,发生这种无法预测的错误,那真是太好了...

Various things can cause this behaviour: 各种因素都可能导致此行为:

  • if some areas of those arrays are never accessed, the corresponding memory pages are never allocated in physical memory; 如果这些阵列的某些区域从未被访问过,则相应的内存页将永远不会分配到物理内存中;
  • your program won't probably use all the arrays at the same time, and at any time only a small slice of every array may be needed; 您的程序可能不会同时使用所有数组,并且随时可能只需要每个数组的一小部分; in such situation, most of your arrays are swapped out of physical memory, dramatically reducing its usage. 在这种情况下,您的大多数阵列都被交换出物理内存,从而大大减少了其使用量。

Without seeing the code, these are the most probable causes. 没有看到代码,这是最可能的原因。

Well, it might be some issue in your code, and you really did allocate less than you think. 好吧,这可能是代码中的一些问题,并且您分配的确实少于您的想象。 Also, what Task Manager shows is what the OS is "handling" at the moment. 另外,任务管理器显示的是操作系统当前正在“处理”的内容。 The memory might have not yet been allocated by the OS for various reasons. 由于各种原因,操作系统可能尚未分配内存。 Try using all that memory to see if the amount shown by Task Manager changes. 尝试使用所有内存以查看任务管理器显示的数量是否发生变化。

To be really sure about what amount of memory is allocated by the compiler, generate a MAP file and find the symbols ( var_name ) and see how much is exactly allocated. 要真正确定编译器分配了多少内存,请生成一个MAP文件并找到符号( var_name ),然后查看确切分配了多少内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM