I have allocated 1GB of memory using malloc.
#include <stdio.h>
int main()
{
int *ptr = malloc(1024*1024*1024UL);
if (ptr)
printf("Memory Allocated\n");
else
printf("Allocation Failed\n");
memset(ptr, 'a', (1024*1024*1024UL));
getchar();
free(ptr);
return 0;
}
Allocation is successful, but i don't see any difference in between the free memory.
Before running the application, my free memory:
$ free -m
total used free shared buff/cache available
Mem: 6906 1398 3457 7 2050 5206
Swap: 2047 0 2047
After running the command, but before pressing enter on the keyboard at the getchar() stage.
$ free -m
total used free shared buff/cache available
Mem: 6906 1398 3457 7 2050 5206
Swap: 2047 0 2047
There is no change at all. So, from where is the memory allocated. It is virtual memory, but it should have a mapping into physical memory which is RAM. Can anyone explain this