The mmap Module
The mmap module supplies
memory-mapped file objects. An mmap object behaves
similarly to a plain (not Unicode) string, so you can often pass an
mmap object where a plain string is expected.
However, there are differences:
An
mmapobject does not supply the methods of a string objectAn
mmapobject is mutable, while string objects are immutableAn
mmapobject also corresponds to an open file and behaves polymorphically to a Python file object (as covered in Chapter 10)
An mmap object m can be
indexed or sliced, yielding plain strings. Since
m is mutable, you can also assign to an
indexing or slicing of m. However, when
you assign to a slice of m, the right-hand
side of the assignment statement must be a string of exactly the same
length as the slice you’re assigning to. Therefore,
many of the useful tricks available with list slice assignment
(covered in Chapter 4) do not apply to
mmap slice assignment.
Module mmap supplies a factory function that is
different on Unix-like systems and Windows.
Reference Section
Methods of mmap Objects
An mmap object m
supplies the following methods.
Using mmap Objects for IPC
The
way in which processes communicate using mmap is
similar to IPC using files: one process can write data, and another
process can later read the same data back. Since an
mmap object rests on an underlying file, you can
also have some processes doing I/O directly on the file, as covered
in Chapter 10, while others use
mmap to access the same file. You can choose ...