mmap resizing macosx unix

David Pratt fairwinds.dp at
Sun Apr 5 21:39:16 CEST 2009

For sake of documenting for list, I ended up opening file a second  
time with 'a', padding it to extend its size (previous size +  
additional bytes to accommodate the insertion), closing file, open  
file with 'r+',  open a second mmap with with new size, moving text to  
new location, then inserting the replacement text. Not quite as smooth  
as doing a resize(), moving text and inserting if this had worked.


On 5-Apr-09, at 11:34 AM, Philip Semanchuk wrote:

> On Apr 5, 2009, at 10:28 AM, David Pratt wrote:
>> 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()
> Hi David,
> Based on experience with my posix_ipc module, ISTR that (a) resizing  
> of the mmapp-ed segment happens via a call to ftruncate() (or  
> os.truncate() in Python land) and (b) OS X only supports one call to  
> this per segment; subsequent calls fail. Keep in mind that I was  
> dealing with shared memory.  A regular mmapped file might resize  
> just fine so point (b) might be irrelevant for you.
> Philip
> --

More information about the Python-list mailing list