Quote Originally Posted by CodeMonkey View Post
mmap() is standardized by POSIX: mmap

So, it's not included in the C standard library, but it is available on Linux, MacOS, AIX, etc.

mmap() tells the system to map a file to the process's virtual memory. read() and its derivatives (fgetc(), etc.) get bytes from a file and copy them into a user-supplied buffer. In the ideal case, mmap() can allow for faster access because you don't need to copy into an intermediate buffer. Also, the C standard functions fgetc() and friends operate on FILE streams, not directly on files. In that case you're copying from the file into a FILE buffer and then possibly into a user-supplied buffer.

mmap() isn't certain to make your program faster, but it will make your program more complicated and less portable.

If your program is heavy on I/O and a profiler tells you that you're spending a lot of time in read/write syscalls, then you might consider switching to mmap() and see whether performance improves. Otherwise, I'd stick with the standard functions.

Thank you! I understand your points and I agree! I will keep using "read"! Have a nice day my friend!