On 13 May '08, at 12:55 PM, Daniel Vollmer wrote:

It sounds like you're creating a single NSString containing the entire contents of the file, then?

Yes. Is that something I shouldn't do? I mean, I feel a tiny bit silly creating such huge strings but I didn't find a nice alternative (e.g. like the Ruby for each line iterators on file objects).

Unfortunately streams are not Foundation's strong suit. You can use NSStream or NSFileHandle to read incrementally from a file, but the API's pretty low-level and you'll have to do things like decoding UTF-8 and parsing for line ends by yourself.

But now that means that the strings are "endangered" from in-place file modification for the lifetime of my objects created during parsing, not just the initial parsing itself, correct?

The big 20MB string might be, yes. If you created any new NSStrings as substrings of it, I am pretty sure those have their own copies of the character data, so they should be immune.

Note that even if you used a stream to read the file incrementally, you wouldn't be immune to something else modifying the file while you were reading it. So the effect isn't all that different. Just be sure to release and stop using the big 20MB string right after you finish scanning it.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to