NSData Vs NSFileHandle For Extracting From Archive Files
NSData Vs NSFileHandle For Extracting From Archive Files
- Subject: NSData Vs NSFileHandle For Extracting From Archive Files
- From: Duncan Anker <email@hidden>
- Date: Fri, 21 Apr 2006 15:15:35 +1000
Hi all,
I'm playing around with extracting files out of 'archives', e.g. WAD,
PAK, GRP, BIF or other numerous similar formats, basically files that
consist of an index with offsets and/or lengths, followed by the file
data. I am trying to determine the merits of using NSData against the
probably more traditional NSFileHandle approach.
NSData looks quite seductive in that it is possible to init with a
file's contents and then extract sub-data using the offset and length to
create ranges as needed. My main concern is with attempting to read
files of 50Mb or more in one go. My understanding is that NSData will
implicitly manage virtual memory although I am not too clear on the
implications of this. Does it make a copy of the file, memory map onto
the original file, or possibly implement an internal FileHandle to read
as required? When I experimented with this a few days ago, I noticed the
hard drive seemed to thrash for a few seconds when the file was accessed
which made me wonder how much was being loaded and what was being left
for on-demand.
The NSFileHandle approach, which is what I am still using for the
moment, seems like it might offer finer control over the loading of
data, since it would most likely fetch what was asked for rounded to the
nearest block rather than potentially fetching a few megabytes that are
not needed. However this is pure speculation and for all I know NSData
is implemented on top of a FileHandle anyway. The downside of the
filehandle approach is the requirement of needing to seek and read
separately, thereby requiring 2 calls for each datum and minimising the
usefulness of ranges, since length and offset are used independently.
Does anyone have any suggestions, advice, or possible further pros and
cons of each method? If there is a better way of achieving this than
either of these approaches, I'd be interested in hearing about that, too.
ADV THANKS ANCE
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden