简体   繁体   中英

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 . 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... ? I am using 10-15 really long multidimensional arrays like .. 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...

#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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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