How is it possible for a laptop to have so much memory?

I was messing with malloc calls and I was wondering how much memory my OS can 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 approximately 18 terabytes. Is it possible for a laptop to have so much memory? If this is not possible, how can this be explained?

+5
source share
1 answer

A 64-bit OS can generate a huge amount of address space. What would it limit?

Backup of the address space with physical memory (RAM) is performed only if necessary.

All malloc calls must return an address. This address should not refer to physical memory until you try to read it or write to it.

The disadvantage of this behavior is that refusing to call malloc is usually just an implementation to tell you that you cannot have the memory you are asking for. After that, all the system can do is stop the process when it tries to use more memory than the system can return.

Your implementation will almost certainly give you some way to control this behavior, either at the system level, for each process, or both.

+7
source

Source: https://habr.com/ru/post/1269235/


All Articles