• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Opening a file read-only?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opening a file read-only?


  • Subject: Re: Opening a file read-only?
  • From: Wade Tregaskis <email@hidden>
  • Date: Wed, 10 Aug 2011 08:10:52 -0700

> Try running fs_usage while your app is running, and you’ll be able to see what files it opens and in which modes.
> (Or there’s probably an Instrument for that now?)

There's half a dozen related to file I/O, which unfortunately makes it very awkward to use for even simple tasks like this.  You also need to manually add in the VM instrument, since it's not in the "File Activity" template, in order to see the actual mmap.  fs_usage is much faster.

On 10.7 -[NSData initWithContentsOfMappedFile:] opens the file read-only.  So does -[NSData initWithContentsOfFile:].  Even if you instantiate an NSMutableData instead, the file is still opened read-only.  I have not tested on iOS, but I'd be surprised if it were any different.

Note also that initWithContentsOfMappedFile: is deprecated in 10.7.  There doesn't appear to be a replacement; I presume you're supposed to use initWithContentsOfFile:, but that really does read the entire file in at init time (into a single malloc allocation, no less)._______________________________________________

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

  • Follow-Ups:
    • Re: Opening a file read-only?
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Re: blocks and retaining CoreFoundation objects
  • Next by Date: Re: NSTableView: move rows through drag and drop?
  • Previous by thread: Lion autosave: Undefined st_flags 0x40 bit being set, causing errors
  • Next by thread: Re: Opening a file read-only?
  • Index(es):
    • Date
    • Thread