mmap resizing macosx unix

David Pratt fairwinds.dp at
Sun Apr 5 16:28:26 CEST 2009

Hi. I have been experimenting with mmap recently. I determined how to  
read and write properly from it and so search and replace on large  
files. The problem I am having is with replaces that are larger than  
the mmap. In this instance I need to

* rewind
* resize the mmap to accomodate the text
* move some part of the text to a new location on the mmap so the new  
text does not overwrite the old
* write the replacement text

When I try to use resize it gives me the following error;

SystemError: mmap: resizing not available--no mremap()

I pass size to mmap to begin with based on  my filesize

size = os.path.getsize(filename)

m = mmap.mmap(f.fileno(), size)

I am attempting to give it new size by doing:

m.resize(size + size_diff)

size_diff is difference between original and what will be new file  
size after the insertion.

Can someone provide some hint on resizing or its this a python bug?  
Many thanks


More information about the Python-list mailing list