I’ve been considering using mmap for file reading, and was wondering how portable that is.
I’m developing on a Linux platform, but would like my program to work on Mac OS X and Windows.
Can I assume mmap is working on these platforms?
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.
The
mmap()function is a POSIX call. It works fine on MacOS X (and Linux, and HP-UX, and AIX, and Solaris).The problem area will be Windows. I’m not sure whether there is an
_mmap()call in the POSIX ‘compatibility’ sub-system. It is likely to be there — but will have the name with the leading underscore because Microsoft has an alternative view on namespaces and considersmmap()to intrude on the user name space, even if you ask for POSIX functionality. You can find a definition of an alternative Windows interfaceMapViewOfFile()and discussion about performance in another SO question (mmap()vs reading blocks).If you try to map large files on a 32-bit system, you may find there isn’t enough contiguous space to allocate the whole file in memory, so the memory mapping will fail. Do not assume it will work; decide what your fallback strategy is if it fails.