A
Alo Sarv
Hi
From what I have understood from various posts in this newsgroup, writing event
loops pretty much comes down to this:
while (true) {
handleEvents();
sleep(1); // or _sleep() or nanosleep(), depending on platform
}
The problem is that sleep() sleeps at minimum the delay given, but may sleep
longer. Initially I thought this wasn't a problem, until I ran some tests:
On P4/2.6ghz/WinXP, it runs ~500 loops per second ( 2ms avg sleep)
On P4/2.6ghz/Linux 2.6.5, it runs ~250 loops per second ( 3ms avg sleep)
On Cel/400mhz/Linux 2.4.20, it runs ~30 loops per second (20ms avg sleep)
These times were measured with idle event loop, e.g. no events were
posted/handled. On the P4 system, its all good, however I'm concerned about the
30 lps on low-end systems. Since this is idle looping, as soon as I start
posting/handling large amounts of events, it will drop even lower...
I'm not sure, but doesn't that make the app extremely slow? Are there any other
event loop mechanisms besides the above? I did a fair amount of searching over
google but came up pretty emtpy-handed on the topic of writing event loops.
Perhaps someone can suggest a book / website on the topic?
Alo Sarv.
From what I have understood from various posts in this newsgroup, writing event
loops pretty much comes down to this:
while (true) {
handleEvents();
sleep(1); // or _sleep() or nanosleep(), depending on platform
}
The problem is that sleep() sleeps at minimum the delay given, but may sleep
longer. Initially I thought this wasn't a problem, until I ran some tests:
On P4/2.6ghz/WinXP, it runs ~500 loops per second ( 2ms avg sleep)
On P4/2.6ghz/Linux 2.6.5, it runs ~250 loops per second ( 3ms avg sleep)
On Cel/400mhz/Linux 2.4.20, it runs ~30 loops per second (20ms avg sleep)
These times were measured with idle event loop, e.g. no events were
posted/handled. On the P4 system, its all good, however I'm concerned about the
30 lps on low-end systems. Since this is idle looping, as soon as I start
posting/handling large amounts of events, it will drop even lower...
I'm not sure, but doesn't that make the app extremely slow? Are there any other
event loop mechanisms besides the above? I did a fair amount of searching over
google but came up pretty emtpy-handed on the topic of writing event loops.
Perhaps someone can suggest a book / website on the topic?
Alo Sarv.