I'm kind of confused by mmap
.
Well, I know that when we malloc
a big size of memory, we will invoke the function mmap
, which will allocate an area in memory. In this case, mmap
just allocate some memory for some process.
However, I've heard that mmap
is a kind of technique, which allows us to map a file, which is located on the hard drive, to the memory so that we can have a better performance comparing with normal IO (read & write).
For me, the two things above are totally two independent stories: one is about allocation of memory, the other is about reading and writing files with a better way.
But why are both of them called mmap
? Is it just a coincidence or they are actually the same technique?