3 ms·
> Properly used mmap is very nice but some people are getting carried away with the superlatives. Well, it all depends on your access patterns. The bottom lin
by beagle3 13y ago
> Properly used mmap is very nice but some people are getting carried away with the superlatives.
Well, it all depends on your access patterns.
The bottom line is: in a modern (later than 1985 or so) Unix system, mmap is hardware based virtual memory; read() and write() can give you software based virtual memory. Who do you think is going to have better performance?
Compare and contrast:
a) mmap an 8GB file into 64-bit address space, start using immediately. only stuff you actually use gets read from disk.
b) using only read() access, read what you need, manage caching to avoid syscalls, etc.
It is unlikely b) can be faster at all, and it will only be competitive if the granularity of reading + the cost of cache management is low.
In cases where either granularity or cache management is expensive (which is common), mmap is likely to win big time.