i have question about C language (memory). this is my source
#include <unistd.h>
int main() {
char ___storage___[1073741824];
sleep(30);
return 0;
}
RAM Usage : 10 Bytes
when i run this program i expected this program get 1 GB from my pc ram for 30 seconds. but it's get nothing from my PC ram !!! but for example if i copy the characters into this array like this
#include <stdio.h>
#include <unistd.h>
int main() {
char ___storage___[1073741824];
for (int i = 0; i < 536870912; i++) // 512 Mb characters !
___storage___[i] = 'h';
sleep(30);
return 0;
}
RAM Usage : 512 MB
for this program when i run it, this program get 512 MB of my ram ! but i declared a variable with (1GB) size ! why ? if this get our PC ram only when we insert something inside it, why we have dynamic variables !? for example we give a dynamic variable high range and insert inside it with out dynamic allocation or reallocation !