David:

Thanks for your help, this seems like a class that will be perfect for what
I am doing!  Just a few questions:

1. Is there any concern of thread safety using this class?
2. How can I pass NSFileHandle the file URL of my files?
3. How could I create a method that will take the contents of the file and
do something with them?

Sorry about the big questions. ;)


Sincerely,

Pierce Freeman


On 4/4/09 9:10 PM, "Dave Keck" <davek...@gmail.com> wrote:

>> Yeah, it really helped!  I am trying to get the contents of the files in a
>> certain directory, so I think that I could probably get away with using a
>> timer.
> 
> In this case, the reason your task is taking several seconds to
> complete is most likely attributed to the sheer time it takes the read
> the contents of the files; that is, most of the time that it takes for
> the lengthy-task to complete isn't due to lots of
> computation-intensive stuff going on, but rather the age-old slow disk
> read. On the list of the 3 best times to use threads, reading large
> files from disk would perhaps be one of them...
> 
> I probably should have asked for more information before forming my
> last post - for this case in particular, I would use NSFileHandle's
> asynchronous file reading mechanisms (which create separate threads
> for you, so you don't have to worry about it). Read about NSFileHandle
> in the docs, specifically, check out
> -readToEndOfFileInBackgroundAndNotify.
> 
> At any rate, to get the contents of every file in a directory, I would
> iterate over the files in the directory, creating an NSFileHandle for
> each one, and call -readToEndOfFileInBackgroundAndNotify for each.
> Depending on how many files you're expecting, you may need to call
> -readToEndOfFileInBackgroundAndNotify on a small number of
> NSFileHandles, wait until those have finished reading, call it on the
> next group of NSFileHandles, etc.
> 
> Note that while you may have escaped from using threads this time
> (directly, at least) that's not always going to be the case :).
> Threads are indispensable and with the number of cores chips are
> sporting these days, will only become more so...
> 
> Good luck!
> 
> David


_______________________________________________

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