Hmmm...well fread reads data from a device in an amount you specify from an open file descriptor. There are cacheing aspects to fread, or their can be.
mmap of course "maps" the file into memory. On most OS's no data is actually read until the user tries to access it. On most OS's the latest page accessed will be cached in memory and perhaps all the pages read will be.
Which one works "best" in your situation depends on ......well your situation. How many other processes are running. Are they also accessing the disk? If you are reading the data in, why wouldn't you cache it in memory instead of re-reading?
Usually , your application will dictate which is better.
For instance - if you are loading code that will be accessed or linked with other application code - mmap would be best.
fread is a "high level" function that enables you to read a part of a file into a memory buffer. mmap is a more "low level" function (i.e. system call) that directly lets you map the file into memory (e.g. use it as if it were a memory region referenced by a pointer). If you need to read only selective parts of the file repeatedly, go for fread and use a custom caching method to repeat reads only if absolutely necessary. Otherwise, mmap is almost always faster, because caching happens automatically at kernel level.
If you use fread(), there will always be overhead from the system call API (int 80, trapping into kernel space) while the mmap() let you set up once of the page table mapping for the file content and all the subsequent memory operation is done without trapping into kernel space.
Of course, when the disk block is accessed for the first time, it has to be populated into page cache, and this is the price that both fread() and mmap() need to pay.
Thus, if you need to repeatedly access the same file content, then mmap() will work better under the condition that your page cache is large enough to hold the content that you are accessing.
Another difference is the possibility to write. With memory mapping your file is used like the swap part of some memory page. If you change the read values in memory you may synchronize it with file with "msync".
mmap have more options for exemple you may share the mapped file with other program and so they can read the modification without need of a real write on disk. Another possibility is to use "madvice" function to give to system advice on the way to use cache depending of the way you want to read the file. For exemple, you may say that you will read a given part of the file in the future in order to trigger if possible the reading of this part in advance.
fread une stream (FILE*) dans mmap use file descriptor. The equivalent of fread with file descriptor is simply the function "read".
fread() is a buffered read function. Will do ok for small files.
mmap() maps a file (or nothing) to a new memory page(s). Probably will work well on large files. You get a pointer and can treat the file as a memory array and let the OS worry about the rest. There are flags that can improve the performance depending on the usage. Read man 2 mmap.
Also read what Linus once said about mmap: http://bit.ly/ScoZdA
Bottom line: implement using both, then test the performance using appropriate benchmarks.
mmap ensure different processes sharing a file by mapping it into memory. When address mapped, processes can access it as ordinary file instead of using read(), write(). But it actually does not allocate space on the disk. So when you ensure the info is not rubbish and will not regret, call msync() to save to disk. Hope this is not rubbish.