[ANN] Memory mapped files for POSIX and Windows

Gracjan Polak gracjanpolak at gmail.com
Tue Mar 18 09:46:28 EDT 2008


Hi all,

I just uploaded mmap to hackage:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mmap

The package provides memory mapping abstractions for both POSIX and Windows
systems like Vista, Linux and Mac OSX. This library provides a wrapper to
mmap(2) or MapViewOfFile, allowing files or devices to be lazily loaded into
memory as strict or lazy ByteStrings, ForeignPtrs or even plain Ptrs, using
the virtual memory subsystem to do on-demand loading. Modifications are also
supported.

Package includes a cp-like copy utility that uses different mechanisms to copy
contents of file. Here come some statistics from using it on 90MB file:

Windows:
Prelude copy: 10.453 sec
ByteString copy: 0.625 sec
ByteString.Lazy copy: 0.516 sec
MMap copy: 0.281 sec
MMap copy lazy: 0.250 sec

Linux:
Prelude copy: 3.332 sec
ByteString copy: 0.280 sec
ByteString.Lazy copy: 0.292 sec
MMap copy: 0.264 sec
MMap copy lazy: 0.200 sec

Mac OSX ppc Tiger 10.4
Prelude copy: 5.719 sec
ByteString copy: 0.701 sec
ByteString.Lazy copy: 0.864 sec
MMap copy: 1.073 sec
MMap copy lazy: 1.414 sec

Hardware is different on those systems, so only relative comparison makes sense.
Memory mapping provides significant advantages on Windows and Linux, not so on
Mac OSX. Seems like mmap on Mac is not very well implemented.

Any feedback is welcome!

--
Gracjan




More information about the Libraries mailing list