Re: Alternative to Delay()
Re: Alternative to Delay()
- Subject: Re: Alternative to Delay()
- From: Howard Moon <email@hidden>
- Date: Tue, 29 Jul 2003 13:29:16 -0700
On Tuesday, July 29, 2003, at 12:53 PM, Brian Willoughby wrote:
The best multi-processing techniques are to write your code so that it
is
completely event driven and re-entrant. When you handle mouse down,
for
example, set some state variables and remember some coordinates and
then
return. Then, your application is not taking any CPU or executing any
instructions until the next event comes in. If the next event is a
mouse moved
event, your handler can use the state variables and starting mouse
position to
display any intermediate results, update appropriate state variables,
and
again return without looping. You will eventually receive a mouse up
event
which should signal the final result that the user's mouse drag gesture
indicates. By returning immediately after processing a single event,
you
guarantee that your app is not taking any more CPU than the absolute
minimum
needed.
Coding in this third method is not traditional Mac programming. It
also may
only be possible in Cocoa (I've never written a pure Carbon app).
And, most
important, many programmers have trouble organizing their code this
way without
the convenient localization of a loop. But it is the only way to be
totally
re-entrant and avoid excess CPU instructions that a looping construct
creates.
Fewer instructions means less CPU usage. Event loops are a crutch :-)
\
That method of handling mouse events is exactly what should be done in
Carbon as well. You install a Carbon Event handler that gets the mouse
down, mouse move and mouse up events (and keystrokes, too, if desired),
and respond immediately to the event and drop back out. It works very
well from my experience.
-Howard Moon
Antares Audio Technologies
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.