I'm studying how virtual memory works and I'm not sure what happens if I load a big file (smaller than the physical memory, though) with fread()
and similar.
As far as I understand, the operating system might not allocate the entire corresponding physical memory. Instead, it could wait until a page fault is triggered as my program reads a specific portion of the file (a portion not yet mapped to physical memory).
This is basically the behavior of a memory mapped file. So, if my assumptions are correct, what is the benefit of using system calls like mmap()
? Just to avoid the usual for-loop dance when reading with fread()
, maybe?