On Aug 20, 2016, at 10:59 , Andreas Falkenhahn <andr...@falkenhahn.com> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to