c++ - Why is the heap after array allocation so large -
i've got basic application boils down following code:
char* gbigarray[200][200][200]; unsigned int initialise(){ for(int ta=0;ta<200;ta++) for(int tb=0;tb<200;tb++) for(int tc=0;tc<200;tc++) gbigarray[ta][tb][tc]=new char; return sizeof(gbigarray); }
the function returns expected value of 32000000 bytes, approximately 30mb, yet in windows task manager (and granted it's not 100% accurate) gives memory (private working set) value of around 157mb. i've loaded application vmmap sysinternals , have following values:
i'm unsure image means (listed under type), although irrelevant of value around i'm expecting. throwing things out me heap value, apparent enormous size coming from.
what don't understand why is? according this answer if i've understood correctly, gbigarray placed in data or bss segment - i'm guessing each element uninitialised pointer placed in bss segment. why heap value larger silly amount required?
it doesn't sound silly if know how memory allocators work. keep track of allocated blocks there's field storing size , pointer next block, perhaps padding. compilers place guarding space around allocated area in debug builds if write beyond or before allocated area program can detect @ runtime when try free allocated space.
Comments
Post a Comment