Re: Using notifications vs. listener lists
Re: Using notifications vs. listener lists
- Subject: Re: Using notifications vs. listener lists
- From: Drew McCormack <email@hidden>
- Date: Sun, 5 May 2002 10:49:20 +0200
On Sunday, May 5, 2002, at 01:11 AM, Dave Fayram wrote:
Hi,
I'm working on a cocoa app that relies heavily on libpcap and I
realized I have a small
design dilemma I don't know the "cocoa" solution for. My little worker
thread is going to be
reading packets of the bpf and it needs to let people know when it
recieves appropriate
packets from various hosts. Sometimes, there could be long periods of
time without any
packets, sometimes there could be hundreds a minute. I'd like to be
able to register multiple,
arbitrary listeners to respond to these events.
My first reaction is to use the NSNotificationCenter and register
listeners (passing the
germane info via the userinfo field) but I don't know if I should use
an NSArray of listeners
and enumerate across that. What is the "Cocoa" way here? I'd like
performance to be decent
as well and I really don't know how well NSNotifications work in terms
of speed.
Could someone fill me in?
Posting notifications is definitely the way to go in Cocoa. There can
sometimes be a problem with performance if there are a lot of
notifications, but you can also coalesce them to improve performance.
Check out the docs for NSNotificationQueue to see how to do this.
Drew McCormack
- Dave "Paradox" Fayram
My ElGamal and DSA keys can be found at:
http://zero.atomictrain.net:88/~paradox/pgpkey.html
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ...
Dr. Drew McCormack
Trade Strategist (www.trade-strategist.com)
Trading simulation software for Mac OS X
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.