bytestring-mmap-0.2.2: mmap support for strict ByteStrings

Portabilitynon-portable -- posix only
MaintainerDon Stewart <>
Safe HaskellSafe-Infered




mmap a file or device into memory as a strict ByteString.


Memory mapped files

unsafeMMapFile :: FilePath -> IO ByteStringSource

The unsafeMMapFile function maps a file or device into memory, returning a strict ByteString that accesses the mapped file. If the mmap fails for some reason, an error is thrown.

Memory mapped files will behave as if they were read lazily -- pages from the file will be loaded into memory on demand.

The storage manager is used to free the mapped memory. When the garbage collector notices there are no further references to the mapped memory, a call to munmap is made. It is not necessary to do this yourself. In tight memory situations, it may be profitable to use performGC or finalizeForeignPtr to force an unmap.

Note: this operation may break referential transparency! If any other process on the system changes the file when it is mapped into Haskell, the contents of your ByteString will change.