Memory Mapped Files

mmap module

  • Provides access to memory mapped files and the mmap() system call
    import mmap
     import os
     
     f = os.open("foo", os.O_RDWR)
     m = mmap.mmap(f, 32768, mmap.MAP_SHARED, mmap.PROT_READ | mmap.PROT_WRITE)
     m[10] = 'x'
     print m[200:300]
     m.move(10000,20000,2000)
     ...
     m.close()
     
  • Support anonymous shared memory, private/shared mappings, etc.

Comments

  • Underlying file has to be opened with the same permissions
  • Usually only works in page sized regions (mmap.PAGESIZE).
  • Also works on Windows (slightly different API).
<<< O'Reilly OSCON 2001, New Features in Python 2, Slide 66
July 26, 2001, beazley@cs.uchicago.edu
>>>