NSFileHandle or a better way?
NSFileHandle or a better way?
- Subject: NSFileHandle or a better way?
- From: Jaime Magiera <email@hidden>
- Date: Fri, 30 Jan 2009 09:44:52 -0500
Hi folks,
I've been using NSFIleHandle for a project that inserts data into a
file and synchs it back to disk. Everything went smoothly until the
app started getting used for larger files ( > 200 megs). First, I ran
into the NSFileHandle -> NSData 256 megs conundrum. That was solved
by, as others suggested on this list in other threads, iterating with
readDataOfLength or availableData instead of a single
readDataToEndOfFile. That worked well. I've got pools set up to keep
the memory down. The problem now is that the reads are still really
slow. For example, with a read length of 50 megs, I can only get in 3
reads per second. 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?
thanks for any thoughts,
Jaime Magiera
Sensory Research
http://www.sensoryresearch.net
_______________________________________________
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