On 30 Jan 09, at 06:44, Jaime Magiera wrote:
I've been using NSFIleHandle for a project that inserts data into a file and synchs it back to disk. ... My apps ends up taking almost a minute to perform all of its functions on a file of 500 megs.

Perhaps my overall approach was wrong to start out. What I've been doing is opening a file handle, copying the data after the insertion point to an NSData, truncating the file handle at the insertion point, adding the new data, then adding back the trimmed data. This works fairly well if the insert point is towards the end of the file. However, there are instances where I need to insert a few hundred kb into a the file at a location only a few hundred kb into the file.

xxx ^ xxxxxxxxxxxxxxxxx

The time hit comes from copying the trim data to the NSData. Is there a better way to do this with NSFileHandle? Is there a better way to do this than NSFileHandle?

Not without changing the structure of your file. There's no way to "shift" the contents of a file in the way you're looking for - UNIX file systems aren't structured in a way that permits that. (In fact, I'm not aware of any that are.) You'll need to either rethink how you're storing data, or cope with slow saves.

Incidentally, the way you're doing saving is unsafe. If your application crashes in the middle of a save operation, the file may end up truncated.
_______________________________________________

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 arch...@mail-archive.com

Reply via email to