Re: GetNumEventsInQueue() for Cocoa

2016-08-22 Thread Andreas Falkenhahn
On 22.08.2016 at 01:54 Graham Cox wrote:

> Is it not possible to adapt this model to invoking [NSApp
> nextEventMatchingMask:untilDate:inMode:dequeue]?

Sure, it is, and I'm already using this right now. The problem in my
specific case, however, is that my application is a scripting language.
The user is not forced to write scripts using a waitEvent()-based
model (although he is encouraged to do so). The user may also choose
to poll and hog the CPU. That's up to the script. 

> If your code is truly polling without sleeping, it’s going to be a
> horrible citizen in terms of battery life and CPU hogging. It might
> even be worse than the iOS Facebook app, which is hard to believe ;-)

See above, it's up to the individual script. It is possible to hog
the CPU, but I don't recommend it, obviously.

-- 
Best regards,
 Andreas Falkenhahnmailto:andr...@falkenhahn.com


___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-21 Thread Graham Cox

> On 21 Aug 2016, at 3:59 AM, Andreas Falkenhahn <andr...@falkenhahn.com> wrote:
> 
> Longer story:
> 
> Yes, I know, my app isn't doing things the Cocoa way but that's not possible
> because it's a multi-platform app written in C and I need to make the Cocoa 
> backend
> fit into this fixed, abstracted multi-platform design. Hence, in my 
> NSApplicationDelegate's
> "didFinishLaunching" I'm immediately doing a [NSApp stop:nil] and I'm then 
> processing
> events manually using an old-school model of waitEvent() and handleEvents().
> Unfortunately, the OS-independent backend calls handleEvents() really, really
> often so I need a throttle to avoid killing performance of my app. The timer
> throttling event loop execution to 100 times per second plus 
> GetNumEventsInQueue()
> worked like a charm on Carbon. But now I'd need a Cocoa equivalent for
> GetNumEventsInQueue()... 


Is it not possible to adapt this model to invoking [NSApp 
nextEventMatchingMask:untilDate:inMode:dequeue]?

This method will sleep until there’s an event to handle, so the caller can’t 
force it to go any faster than it needs to go naturally. Even if the generic 
model code calls WaitEvent in a tight loop, if WaitEvent calls down to this, 
you aren’t really polling. Even better would be to break that loop into a 
NSRunLoop, but it may not be possible, depending on the design of the code.

If your code is truly polling without sleeping, it’s going to be a horrible 
citizen in terms of battery life and CPU hogging. It might even be worse than 
the iOS Facebook app, which is hard to believe ;-)

—Graham



___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Gary L. Wade
Cocoa is an object oriented framework that encapsulates a lot of the hard work 
for you, so it doesn’t expose all the low-level details that it manages.  Some 
of the lower level functionality is available by way of CoreFoundation and some 
exposed C APIs, but there are lots of things not exposed.  If you have a need 
to do polling of events and cannot do it with the current APIs available, write 
a radar up and possible open a tech support incident.
--
Gary L. Wade
http://www.garywade.com/ <http://www.garywade.com/>
> On Aug 20, 2016, at 2:26 PM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> Well, yeah, that's just because I was absolutely sure that there would be
> a Cocoa equivalent for GetNumEventsInQueue(). I always believed Cocoa to
> have gazillions of features more than Carbon so I was absolutely sure that
> there would be a Cocoa equivalent for such a trivial thing as polling the
> number of events in the queue but apparently Cocoa's event queue API is
> quite ascetic ;)

___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Quincey Morris
On Aug 20, 2016, at 14:26 , Andreas Falkenhahn  wrote:
> 
> such a trivial thing as polling the number of events in the queue

It seems to me quite possible that there might be events that don’t appear in 
the queue until you ask for an event.  That is, a data source of some kind 
might have triggered, but it’s not checked (and turned into an event) until you 
ask. This might be a reasonable optimization in a mature OS, and it might be a 
reason why there’s no “number of events in the queue” API, and why polling is 
neither trivial nor encouraged.

___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Andreas Falkenhahn
On 20.08.2016 at 22:43 Quincey Morris wrote:

> On Aug 20, 2016, at 13:22 , Andreas Falkenhahn <andr...@falkenhahn.com> wrote:



> this is exactly what I wanted to avoid by looking for an equivalent of
> GetNumEventsInQueue().



> Well, OK, but here’s the horse your rode in on:


> On Aug 20, 2016, at 10:30 , Andreas Falkenhahn <andr...@falkenhahn.com> wrote:



> I need something much faster.

Well, yeah, that's just because I was absolutely sure that there would be
a Cocoa equivalent for GetNumEventsInQueue(). I always believed Cocoa to
have gazillions of features more than Carbon so I was absolutely sure that
there would be a Cocoa equivalent for such a trivial thing as polling the
number of events in the queue but apparently Cocoa's event queue API is
quite ascetic ;)

-- 
Best regards,
 Andreas Falkenhahnmailto:andr...@falkenhahn.com


___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Quincey Morris
On Aug 20, 2016, at 13:22 , Andreas Falkenhahn  wrote:
> 
> this is exactly what I wanted to avoid by looking for an equivalent of
> GetNumEventsInQueue().

Well, OK, but here’s the horse your rode in on:

On Aug 20, 2016, at 10:30 , Andreas Falkenhahn  wrote:
> 
> I need something much faster.

and here’s the horse you’re riding out on:

> That’s no big deal for me, since I can live with that tiny delay which doesn't
> seem to be noticable anyway

That’s a much mellower horse. ;)

___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Andreas Falkenhahn
On 20.08.2016 at 22:01 Quincey Morris wrote:

> On Aug 20, 2016, at 10:59 , Andreas Falkenhahn  wrote:
>
> If so, one alternative is to back-load your “thinning” of
> handleEvents() rather than front-loading it. That is, use an algorithm like 
> this:

Actually, this is pretty much what I'm doing right now and what I meant by 
saying that I use a timer that doesn't poll for events more than 100 times
a second.

> Note that this introduces an average/expected delay of 0.005 secs
> before handling an event after the event queue went idle

...and this is exactly what I wanted to avoid by looking for an equivalent of
GetNumEventsInQueue(). But apparently, there doesn't seem to be one. That's
no big deal for me, since I can live with that tiny delay which doesn't
seem to be noticable anyway. I was just wondering whether Cocoa had an
equivalent for GetNumEventsInQueue(). If that isn't the case, then I can
live with what I have here.

-- 
Best regards,
 Andreas Falkenhahnmailto:andr...@falkenhahn.com


___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Quincey Morris
On Aug 20, 2016, at 10:59 , Andreas Falkenhahn  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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Gary L. Wade
This sounds way outside the realm of Cocoa as it doesn’t expose the means that 
you apparently are using to actually get the events, so any solution you’re 
looking for is going to be within that realm, not Cocoa.

With that being said, I’ve worked on plenty of cross-platform apps that tried 
to shoehorn one architecture into another, and if things don’t work the same 
way you’re expecting, you might find greater success by not trying.  If it is 
possible, I would suggest changing your waitEvent and handleEvents to be empty 
functions and rely upon the Cocoa event architecture.  You might try overriding 
NSApplication’s event retrieving methods to pull the results and save them off 
for your original calls.  You might try getting into the guts of runloops.  It 
all depends on what kind of things you need to do with the events before the 
real objects get them and the purpose of your cross-platform architecture.

If the architecture you’re using is something well known, you might get some 
better advice by others who have used it and how they’ve done things the Cocoa 
way.
--
Gary L. Wade
http://www.garywade.com/ <http://www.garywade.com/>
> On Aug 20, 2016, at 10:59 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> On 20.08.2016 at 19:48 David Duncan wrote:
> 
> 
>>> On Aug 20, 2016, at 10:30 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
>>> wrote:
> 
>>> Is there a Cocoa equivalent for the Carbon call
>>> GetNumEventsInQueue(GetMainEventQueue())?
> 
>>> I use this a lot to poll whether there are events in the queue. 
> 
>> Why do you need to poll if there are events in the queue?
> 
> 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, that's why
> I'm looking for a Cocoa equivalent for GetNumEventsInQueue().
> 
> Longer story:
> 
> Yes, I know, my app isn't doing things the Cocoa way but that's not possible
> because it's a multi-platform app written in C and I need to make the Cocoa 
> backend
> fit into this fixed, abstracted multi-platform design. Hence, in my 
> NSApplicationDelegate's
> "didFinishLaunching" I'm immediately doing a [NSApp stop:nil] and I'm then 
> processing
> events manually using an old-school model of waitEvent() and handleEvents().
> Unfortunately, the OS-independent backend calls handleEvents() really, really
> often so I need a throttle to avoid killing performance of my app. The timer
> throttling event loop execution to 100 times per second plus 
> GetNumEventsInQueue()
> worked like a charm on Carbon. But now I'd need a Cocoa equivalent for
> GetNumEventsInQueue()... 
> 
> -- 
> Best regards,
> Andreas Falkenhahnmailto:andr...@falkenhahn.com
> 
> ___
> 
> 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/garywade%40desisoftsystems.com
> 
> This email sent to garyw...@desisoftsystems.com

___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Andreas Falkenhahn
On 20.08.2016 at 19:48 David Duncan wrote:


>> On Aug 20, 2016, at 10:30 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
>> wrote:

>> Is there a Cocoa equivalent for the Carbon call
>> GetNumEventsInQueue(GetMainEventQueue())?

>> I use this a lot to poll whether there are events in the queue. 

> Why do you need to poll if there are events in the queue?

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, that's why
I'm looking for a Cocoa equivalent for GetNumEventsInQueue().

Longer story:

Yes, I know, my app isn't doing things the Cocoa way but that's not possible
because it's a multi-platform app written in C and I need to make the Cocoa 
backend
fit into this fixed, abstracted multi-platform design. Hence, in my 
NSApplicationDelegate's
"didFinishLaunching" I'm immediately doing a [NSApp stop:nil] and I'm then 
processing
events manually using an old-school model of waitEvent() and handleEvents().
Unfortunately, the OS-independent backend calls handleEvents() really, really
often so I need a throttle to avoid killing performance of my app. The timer
throttling event loop execution to 100 times per second plus 
GetNumEventsInQueue()
worked like a charm on Carbon. But now I'd need a Cocoa equivalent for
GetNumEventsInQueue()... 

-- 
Best regards,
 Andreas Falkenhahnmailto:andr...@falkenhahn.com

___

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

Re: GetNumEventsInQueue() for Cocoa

2016-08-20 Thread David Duncan

> On Aug 20, 2016, at 10:30 AM, Andreas Falkenhahn  
> wrote:
> 
> Is there a Cocoa equivalent for the Carbon call
> GetNumEventsInQueue(GetMainEventQueue())?
> 
> I use this a lot to poll whether there are events in the queue. 

Why do you need to poll if there are events in the queue?

> I tried to use
> 
> [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil 
> inMode:NSDefaultRunLoopMode dequeue:NO]
> 
> as a replacement but this is very, very slow in comparison to Carbon's
> GetNumEventsInQueue() API. I need something much faster. Any ideas?
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.com
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

GetNumEventsInQueue() for Cocoa

2016-08-20 Thread Andreas Falkenhahn
Is there a Cocoa equivalent for the Carbon call
GetNumEventsInQueue(GetMainEventQueue())?

I use this a lot to poll whether there are events in the queue. 
I tried to use

[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil 
inMode:NSDefaultRunLoopMode dequeue:NO]

as a replacement but this is very, very slow in comparison to Carbon's
GetNumEventsInQueue() API. I need something much faster. Any ideas?

-- 
Best regards,
 Andreas Falkenhahn  mailto:andr...@falkenhahn.com

___

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