The host OS is a Windows 10, with 16BG RAM. I have Oracle VirtualBox with Ubuntu 18.04 as the guest OS (2GB RAM).
I ran the following program on the guest OS. I could see top listing up to 40GB. But, I did not see the RAM usage of the VirtualBox going beyond 230MB.
How can I see the exact memory counters on the guest and the host?
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <malloc.h>
static size_t total = 0, n = 0;
static char* ptrs[20000] = {0};
static size_t ncur = 0;
static void alloc_more(int more)
{
char* tmp = (char*)malloc(more);
tmp[more/2] = 32;
tmp[more-1] = 41;
tmp[0] = 53;
total += more;
printf("\n allocated total is %lu GB for %p", total/(1024*1024*1024),tmp);
ptrs[++n] = tmp;
ncur = (n*3)/4;
if(ptrs[ncur])
{ memset((void*)ptrs[ncur], 33, more);
}
}
int main(int argc, char* argv[])
{
while(1)
{
alloc_more(atoi(argv[1]));
}
return 0;
}