Re: Deleting an file that's been NSData memory mapped - safe?
Re: Deleting an file that's been NSData memory mapped - safe?
- Subject: Re: Deleting an file that's been NSData memory mapped - safe?
- From: Marcel Weiher <email@hidden>
- Date: Sun, 14 Feb 2016 11:17:31 +0100
> On 11 Feb 2016, at 20:44, Dan Lau <email@hidden> wrote:
>
> If a file has its contents mapped using NSData's
> initWithContentsOfFile + NSDataReadingMappedIfSafe,
> deleting it doesn't appear to affect reading it's mapped contents. Does
> anyone know if NSData uses mmap(2) under the hood to ensure that this sort
> of operation is valid?
[As Jens said: yes]
In fact, file data will stick around as long as you have an open file descriptor or a mapping.
A neat trick for temporary files that you want to make sure get cleaned up is to open() and unlink() immediately afterward.
The file data will be automatically deleted when your process exits.
Marcel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden