Re: Locking mapped files
Re: Locking mapped files
- Subject: Re: Locking mapped files
- From: "Erik M. Buck" <email@hidden>
- Date: Wed, 15 May 2002 14:41:46 -0500
----- Original Message -----
From: "Georg Tuparev" <email@hidden>
>
Folks,
>
>
I would like to use NSData's dataWithContentsOfMappedFile method for
>
working with large data sets. What is the best way to lock this file in
>
order to guarantee that someone does not move, rename or delete it while
>
the file is in use?
>
I could be wrong, but I don't think you have to worry about locking mapped
files (at least with UFS). The file system makes sure that the contents of a
mapped file are not changed or destroyed while the file is open for reading
or writing. If someone moves, deletes, or writes to the file that is already
mapped into memory, the file system does magical things with i-nodes to make
sure things work out OK. This is similar to the way the vm swap file works
and the way application executables are mapped into memory. I think MACH
does not put unused code pages in the swap file. Instead it relies on being
able to read them from the executable file on disk when they are needed. If
an application that is running is changed, the same i-node magic happens to
make the running application continue to work. I think the general technique
is called "copy on write".
I have know idea how this might be implemented in the OS. I don't know if
it works with HFS file systems. I could be completely wrong because it has
been 10 years since I studied this information.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.