mmap interface in Python

Stephan Houben stephan at pcrm.win.tue.nl
Mon Sep 13 04:39:00 EDT 1999


On 10 Sep 1999 16:31:42 +0200, Hrvoje Niksic <hniksic at srce.hr> wrote:
>When discussing Python speed, many people advised me to "slurp the
>whole file in".  The only reason why I didn't like that is the obvious 
>one -- it burns a lot of memory for large files.
>
>But then I remembered: in C under Unix, I would use mmap() to map the
>file to memory, and operate on that memory.  I don't see why the same
>thing couldn't be available in Python -- under Unix at least.

It sounds cool, but I'm not sure if it buys you all that much
performance-wise. If you're afraid to "burn too much memory", well,
the memory gets swapped out, so who cares? If you want to do a
regular expression match, the match() function will scan the entire
file anyhow and cause it to be loaded into core. So in that case,
you don't win anything either.

Finally, by ussing mmap(), you loose compatibility with lesser OSes.

So I'm not sure if you really want this, although it might be cool
to mmap() some of the special files in Linux... 

Greetings,

Stephan




More information about the Python-list mailing list