I continue experimenting with C. I have this program that allows you to decide how much RAM you want to eat.
char * eatRAM()
{
unsigned long long toEat;
unsigned long long i = 0;
float input;
char * pMemory = NULL;
int megaByte = 1048576;
puts("How much RAM do you want to eat? (in Mega Bytes)");
puts("NOTE: If you want to eat more RAM than you have available\nin your system, the program will crash");
printf("\n>> MB: ");
scanf("%f", &input);
toEat = (unsigned long long)(input * megaByte);
pMemory = malloc(toEat);
printf("\n\nEating in total: %llu Bytes\n", toEat);
puts("Check your task manager!\n");
if(pMemory != NULL)
{
printf("\n\nEating in total: %llu Bytes\n", toEat);
puts("Check your task manager!\n");
for(i; i < toEat; i++)
{
pMemory[i] = 'x';
}
}
else
{
puts("\nSeems like that amount of memory couldn't be allocated :( \n");
}
return pMemory;
}
UPDATED QUESTION:
The thing is that... if I enter for example 1024MB it works, I can see in the task manager it is using 1GB of RAM. Even if I enter 1500MB it works..
But if I enter 2048MB it says
Seems like that amount of memory couldn't be allocated :(
or even if I enter 1756MB
Remember I'm new to C, maybe I'm omitting something important related to how OS allows me to access memory, what could it be?