0
votes
long long size = (long long)1*1024*1024*1024;
char *p =NULL;
while (p==NULL)
{
  /* mmap 100MiB of shared anonymous memory */
   p = malloc(size);
   if(!p)
   {
      printf("\nallocation failed for size %ld",size);
      size = size/2;

   }
   else
   {
       printf("\nallocation passed for size %ld",size);
       break;
   }
}
if(p)
{
  printf("\n making persinstant these allocated memory,%p",p);
  /* Touch every single page to make them resident */
  for (i = 0; i < size / 4096; i++)
  {
     printf ("\n%d",i);
     p[i * 4096] = 1;
  }
  sleep(600) // sleep 10 min and analyze the memory used data

 }

free -m [before running after code] Mon Jul 17 07:57:13 CDT 2017 total used free shared buffers cached Mem: 15950 3225 12725 1 263 1076 -/+ buffers/cache: 1885 14065 Swap: 2047 0 2047

free -m [after before running these code] total used free shared buffers cached Mem: 15950 2199 13751 1 263 1076 -/+ buffers/cache: 860 15090 Swap: 2047 0 2047

So if we see i write 1GB data ( very first time allocate successfully) and free -m shows only 1000KB being used.

Can someone help me to fill this gap. how can i verify the exact RAM uses of my code.

Thanks Vijayky88

1
Seems more like C to me than C++Philipp
memory map remains same in c/c++,is there any issue herevijayky88

1 Answers

0
votes

This difference was there because my system gives same output for free -m and free -k and actually it is in mb.