Re: NSOutlineView (or NSTableView) and threaded, live data display
Re: NSOutlineView (or NSTableView) and threaded, live data display
- Subject: Re: NSOutlineView (or NSTableView) and threaded, live data display
- From: "Michael Ash" <email@hidden>
- Date: Thu, 1 Jun 2006 01:26:39 -0400
On 5/31/06, John C. Daub <email@hidden> wrote:
Hello.
I'm looking for input regarding NSOutlineView (or NSTableView) doing a live
display of data as it comes in from worker threads. What I'm looking for
here is input towards ensuring I'm playing nice with Cocoa. If you've been
down this road before, any insights you are willing to share are
appreciated.
My application has a producer-consumer thread architecture. The producer
thread is searching for stuff, when it finds it it passes it over a
thread-safe queue to the consumer thread, which puts the stuff into the
final data store. The data store is then what the table data source uses to
display the data in the table, with an NSTimer firing every 1.0 seconds to
do a -reloadData.
I have not done this personally, but I've talked to people who have
and it seems that the best architecture is to always manipulate the
final data store in the main thread.
For your architecture, this may mean that you simply have the
"consumer thread" be the main thread. Or you may keep the consumer
thread as-is, and simply duplicate the final data store.
In either case, instead of manipulating the store directly and
guarding access with locks, you would wrap the changes up into an
object and ship it to the main thread using
-performSelectorOnMainThread:.... Once it gets there, you can modify
your local data store and then invoke -reloadData. If you're updating
frequently then it would probably be best to throttle your -reloadData
calls to a few times a second.
This avoids the whole locking business (always a good thing), keeps
your refreshing more responsive while eliminating the need to poll,
allows you to remove objects without risking tripping up your data
source, and is generally simpler overall. You can do the whole thing
without having to subclass the view or putting any thread-aware code
into any data source methods.
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden