I was messing with malloc calls, and I wondered how much memory could my OS give me. I tried:
int main() {
char *String = 0;
String = malloc (100000000000000); // This is 10^14
if (String)
printf ("Alloc success !\n");
else
printf ("Alloc failed !\n");
return 0;
}
And... It worked. 10^14 is roughly 18 Terabytes. Is it even possible for a laptop to have so much memory? If that's not possible how can this be explained?
A 64-bit OS can generate massive amounts of address space. What would limit it?
Backing of address space with physical memory (RAM) is only done when needed.
All the malloc
call has to do is return an address. That address need not refer to physical memory until you try to read from it or write to it.
The downside of this behavior is that failing the malloc
call is the usually the implementation's only chance to tell you nicely that you can't have the memory you are asking for. After this, about all the system can do is terminate the process when it tries to use more memory than the system can back.
Your implementation almost certainly gives you some way to control this behavior either at system level, for each process, or both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With