Re: GetNumEventsInQueue() for Cocoa
Re: GetNumEventsInQueue() for Cocoa
- Subject: Re: GetNumEventsInQueue() for Cocoa
- From: Quincey Morris <email@hidden>
- Date: Sat, 20 Aug 2016 13:01:12 -0700
- Feedback-id: 167118m:167118agrif8a:167118s9XDz3Cjra:SMTPCORP
On Aug 20, 2016, at 10:59 , Andreas Falkenhahn <email@hidden> wrote:
>
> Because actually retrieving events is very, very expensive. I already use a timer
> which limits event loop execution to about 100 times per second but I'd like to
> make an exception in case there are currently events in the queue
I don’t understand what you’re saying here. Based on your earlier post, it’s not that retrieving [existing] events is expensive, but that polling for [non-existent] events is expensive. I assume that you never really want to avoid polling if there’s an event available, regardless of how expensive it is the retrieve and/or process the event. Is that correct?
If so, one alternative is to back-load your “thinning” of handleEvents() rather than front-loading it. That is, use an algorithm like this:
1. Initially, retrieve an event from the queue. Just before retrieving the event, record the current time.
2. If there is one, handle it, and set a flag to say an event was handled.
3. If there isn’t one, clear the flag that says an event was handled.
4. When you receive handleEvents(), check the flag. If set, go back to step 1. If not set, and the current time is past step-1-recorded-time plus 0.01 secs, go back to step 1. Otherwise, do nothing.
Note that this introduces an average/expected delay of 0.005 secs before handling an event after the event queue went idle, but does not restrict overall event throughput when there are multiple events available**.
Note also that if handleEvents() is always called frequently, you don’t need a timer. If you can’t rely on it to be called continuously, then you should probably set a timer of your own to “inject” handleEvents() calls into the above at intervals of 0.01 secs.
** If I understood what you wrote earlier, your problem is that (without knowing the number of events queued) you are currently introducing this 0.005 average delay for *every* event that you handle, which slows throughput.
_______________________________________________
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