System.IO.Posix.MMap

bytestring-mmap-0.2.2: mmap support for strict ByteStrings

Copyright | (c) Galois, Inc. 2007
License | BSD3
Maintainer | Don Stewart <dons@galois.com>
Stability | provisional
Portability | non-portable -- posix only
Safe Haskell | None
Language | Haskell98

System.IO.Posix.MMap

Contents

- Memory mapped files

Description

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

Synopsis

- unsafeMMapFile :: FilePath -> IO ByteString

# Memory mapped files

unsafeMMapFile :: FilePath -> IO ByteString

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.