On Jul 6, 2008, at 7:46 AM, Martin Hairer wrote:

This works like a treat and is faster by a factor 3 or so than using
the "Moriarity" implementation. However, it leaves me a bit concerned
about various warnings all over the place concerning the thread
(un)safety of NSTask and NSFileHandle. So my question is: is the kind
of approach that I am taking doable / reasonable? If not, is there an
alternative way of doing this which is more efficient  than the
"Moriarty" code? Thanks a lot in advance for any help / hint,


        NSFileHandle *msgHandle = [standardInput fileHandleForReading];
        [msgHandle waitForDataInBackgroundAndNotify];

- (void)newMessage:(NSNotification *)notification {
NSString *strOutput = [[NSString alloc]initWithData:[msgHandle availableData] encoding:NSUTF8StringEncoding];
        //Process the data
        [msgHandle waitForDataInBackgroundAndNotify];
}

This is what I'm using in one of my Cocoa apps. I don't know if it's faster, but I would assume so, since there is no loop. Also, If i've interpreted the documentation correctly, the method is run in the main thread so you don't have to worry about anything being thread safe.

Omar Qazi
Hello, Galaxy!
1.310.294.1593

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to