• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
      • From: Michael Ash <email@hidden>
    • Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
  • Next by Date: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
  • Previous by thread: Re: Animation, NSProgressIndicator and Bindings
  • Next by thread: Re: Is there a more efficient way to get the first 4 bytes off a NSInputStream to compare
  • Index(es):
    • Date
    • Thread