Re: Efficiently receiving data from an NSTask
Re: Efficiently receiving data from an NSTask
- Subject: Re: Efficiently receiving data from an NSTask
- From: Omar Qazi <email@hidden>
- Date: Sun, 6 Jul 2008 23:24:51 -0700
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 (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