• 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: Data from thread to NSView, efficiently
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Data from thread to NSView, efficiently


  • Subject: Re: Data from thread to NSView, efficiently
  • From: Jacob Engstrand <email@hidden>
  • Date: Tue, 17 Jul 2007 18:45:26 +0200


On 7 jul 2007, at 05.12, William Zumwalt wrote:

I would just like to know if I'm going about this idea correctly. I have a
thread that's constantly passing back status and measurement data via DO
calls to my main process. The bigger the problem, the more data that gets
sent back, tens of thousands of loops easily.



The measurement data is just a few primitive types that, once they reach my
main controller in my apps parent process, I then pass into another
controller (via [recv msg]'s) so that a graph view gets updated where I draw
the results in Quartz.



Where I'm questioning my process is ... there's just so many method calls.
In my child thread it's a continuous loop of calculations where data is
passed back to the main thread. That's a whole bunch of method calls ...
err, or messages to the receiver and I don't know if there's not a better
way in cocoa that I'm not aware of or how to tell if I'm overloading through
DO and not bottlenecking something along the way if there's really a lot of
overhead here.



It works, but it just doesn't seem right. Is there a better way, or is that
wrong?



Most of Apple's threading examples involve DO, and DO works really well but is often overkill. This should be easier (provided you want to use Foundation classes):



The Consumer object spawns a producer thread...

	Producer* producer = [Producer new];

[NSThread detachNewThreadSelector: @selector (produceSomeDataAndSendToConsumer:)
toTarget: producer
withObject: self];



...the Producer can then hand over data to the main thread as it becomes available...


	[theConsumer performSelectorOnMainThread: @selector(newDataAvailable:)
					withObject: someData
				 waitUntilDone: NO];

And, of course, if the producer is "too fast" for the consuming main thread, it should accumulate batches of data and send them of to newDataAvailable: in chunks. Or, if you _know_ there will be data and so won't loose performance by polling, let the Producer put the data in a shared NSArray, and set an NSTimer to let the main thread harvest the shared NSArray every now and then.

Delivering data _to_ a thread can be done with much less overhead (very simply using an NSArray to share the data between the threads), using MPWaitOnSemaphore() and MPSignalSemaphore().

Hope this helps.

jak


_______________________________________________

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: Data from thread to NSView, efficiently
      • From: Chris Hanson <email@hidden>
References: 
 >Data from thread to NSView, efficiently (From: "William Zumwalt" <email@hidden>)

  • Prev by Date: Re: Menu and NSDocument
  • Next by Date: NSImage & memory
  • Previous by thread: Data from thread to NSView, efficiently
  • Next by thread: Re: Data from thread to NSView, efficiently
  • Index(es):
    • Date
    • Thread