| Module Info
| Add a review of File-Map
This is a well designed module and is nearly always preferable to the classic Sys::Mmap. Unlike Sys::Mmap, it will clean up mappings when they are no longer needed because all variables referencing them have gone out of scope.
A couple minor issues with File::Map:
* File::Map contains partial interfaces to msync/mlock/mprotect/madvise. I feel that these interfaces should be in separate modules, not bundled together with a file mapping module since they can be useful even when you aren't directly using mmap().
* There is no way to create MAP_FIXED mappings (although you generally don't need this).
* The dependency tree seems slightly excessive.
Although not an issue with this module, as it says in the documentation you should be aware that there is a bug in perl versions before 5.17.5 where regular expressions can read one byte past the end of a string. This can segfault your perl process if you create mappings that are exact multiples of your page size (and your OS doesn't create adjacent mappings):
$ uname -a
OpenBSD saturn 5.1 GENERIC#181 amd64
$ perl -E 'say $^V'
$ perl -MFile::Map -e 'File::Map::map_file my $str, "/dev/zero", "<", 0, 4096; $str =~ /.$/'
Segmentation fault (core dumped)
Traditionally, programs read information from a file by opening a file handle, reading data into memory, then closing the file handle. This module takes a different approach: it provides a scalar variable that magically corresponds to a file's content on disk without reading any new data into memory.
If you find yourself working with files of large or unknown size, this module saves you having to worry about the memory that perl might allocate.
Behind the scenes, the module uses mmap on Unix to do its magic. The module uses similar facilities on Windows and VMS, making it portable to most platforms that Perl developers often use.
I like this module because it combines the easiness of File::Slurp (or setting $/ to undef for those who like minimal dependencies) and the efficiency of other interfaces to mmap, such as Sys::Mmap, along with the benefit of better portability.
The import interface is wonky (why make people write a bunch of ":foo"?), but this module is heading in the right direction.