If I am right, on Linux (in C/C++, gcc/g++), one can read data from a regular file using read(2) or mmap(2) syscalls.
Two questions. Do read syscall use mmap internally? When is first faster than the second and vice versa?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re reading the file sequentially, my default choice would be to repeatedly
readinto a largish buffer.If you’re accessing small bits of data scattered around a large file, the choice is less clear, but
mmapcould lead to more readable code (since you could code things up as if the file were already in memory). Which would give better performance in this case is hard to tell a priori.If you’re writing performance-critical code, then the only way to ascertain performance is by benchmarking/profiling actual code.