3 ms·
Small side note for completeness: The effects of oh-noes-my-file-is-gone can be somewhat mitigated by using the heuristics built into NSData (instead of using
by Hackbraten 8y ago
Small side note for completeness:
The effects of oh-noes-my-file-is-gone can be somewhat mitigated by using the heuristics built into NSData (instead of using mmap directly).
For example, you call NSData’s `dataWithContentsOfFile:options:error:` with the `NSDataReadingMappedIfSafe` option [1]. The framework will then transparently mmap the file unless it believes there’s an elevated risk of the file going away.
Apple doesn’t disclose how NSData exactly makes that decision; however, I’ve found a few reports that say it uses mmap internally when the file is on the root filesystem, and fall back on an in-memory copy otherwise.
It’s a rather dumb heuristics though, and may not solve the issue entirely.
[1] https://developer.apple.com/documentation/foundation/nsdatareadingoptions/nsdatareadingmappedifsafe https://developer.apple.com/documentation/foundation/nsdatar...
- saagarjha 8y agoThe method also checks for things like whether the file is in /dev and whether filesystem compression is enabled.
- ben-schaaf 8y agoWouldn't that mean that networked files would be loaded entirely into RAM, negating the whole reason we started using mmap in the first place?