Re: appending to a memory-mapped file
Re: appending to a memory-mapped file
- Subject: Re: appending to a memory-mapped file
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 6 Jan 2010 22:39:26 +0100
Le 6 janv. 2010 à 17:36, Jens Alfke a écrit :
>
> On Jan 6, 2010, at 6:11 AM, Joel Reymont wrote:
>
>> Forgive me if I'm missing something obvious but how do you append to a memory-mapped file?
>> The file will obviously grow when you append to it but what's the best way to 'extend' the memory representation?
>
> I've looked into this too. A memory-map applies not to the entire file, but to a range of bytes; and there's no way to modify one in place. You have to create a new mapping using mmap on the byte-range you added to the file. In general this means the maps will be discontiguous in address space. If that's not acceptable, you can try to reserve more address space than you need, use the beginning of it for the file map, and then position your extended maps after the first one (until you run out of space...)
>
> I'm not an expert, just quoting from memory. I haven't tried to do the contiguous-allocation stuff myself. Look in the list archives, either in this list or darwin-userlevel, circa Oct/Nov, for my questions and the answers I got.
Just an idea, you can try to remap the same file with a larger size at the same address than the previous one using the MAP_FIXED flag. According to the man page, if you pass this flag, mmap try to "remove a mapping that already exists at that location". So it will automatically invalidate your previous mapping and create a new one with the new range (if there is enough room to do this of course, else it will failed). And it is the same file, the memory content should not change. I don't know if the OS try to optimize the operation by detecting that this is the same fd, and preserve the memory in this case.
-- Jean-Daniel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden