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: email@hidden
- Date: Sun, 14 Feb 2016 20:45:25 +0900
> On Feb 14, 2016, at 7:17 PM, Marcel Weiher <email@hidden> wrote:
>
>
>> 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
>
>
> _______________________________________________
>
> /
Would the file itself be accessible by another process before your process exits?
_______________________________________________
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