Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
- Subject: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
- From: William Jon Shipley <email@hidden>
- Date: Tue, 27 Jan 2009 14:15:54 -0800
Will thanks for the heads up, for my purposes this time around, the
input stream will be coming in off the file system, but I did not want
to load the whole thing into an NSData object.
Ah! Well, your approach will work, but if your file is less than 4GB I
highly recommend something like:
NSData *fileData = [NSData dataWithContentsOfFile:path
options:NSUncachedRead error:&error];
This is NOT implemented by Apple in a naïve way - eg, it doesn't read
the whole dang file and blat it into memory. Instead, it reads blocks
on-demand, in a most efficient manner.
In my tests "NSUncachedRead" is very, VERY fast, great if you are only
going to use each byte once. "NSMappedRead" has a different set of
constraints but can also be very fast.
-Wil_______________________________________________
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