Mail Archives: djgpp/1999/02/04/06:03:27
is05562 AT salleURL DOT edu writes:
>>> I've been coding some stuff with djgpp, and I've been using the
>>> "whole" allegro only for the keyboard handler. But I think that if
>>> I wrote my own keyboard handler the application I'm coding would
>>> be faster
>>
>> but it won't be measurably faster.
>
> The thing is that with allegro keyboard handler, and my program,
> I have to check some array variables every 1/50 sec, EVEN THERE
> HASN'T been a key press/release, and now if I write my own keyboard
> handler, this check will only occur when a key has been pressed /
> released ONLY! This surelly will save me a lot of CPU cycles
Personally, I wouldn't count a few checks every 1/50 of a second as
being in the worth-optimising category: I would be amazed if you could
even get the profiler to notice such a trivial bit of code! But you
are right that it is marginally faster if you can direct the interrupt
straight to your event code (although you could use the Allegro
keyboard_callback or keyboard_lowlevel_callback hooks for this).
> BTW also, maybe I didn't wanted to actually read the 0x60 port,
> but only actualizing the "leave" variable... In both cases the
> inport 0x60 seems to be necessary though...
Yes. Without the read, you will only get a single interrupt, because
the keyboard controller won't respond to any more input until you've
read and dealt with the first keypress. If you leave out the port
access from your handler, it has no way to realise that you have
got around to processing this event yet, so it will be stuck waiting
around until you do something about it.
> BTW also, a new doubt came to me... If I "allocate" an IRET wrapper,
> MUST I deallocate it explicitly?
If you don't, you will be leaking memory. In practice this will be
freed automatically when your program exits, but IMHO it is still
cleaner and more robust if you do this explicitly yourself.
If you ever allocate a realmode callback (eg. for hooking into
the mouse driver movement event), it is very important to free
those, because at least some DPMI servers won't automatically
free real mode memory blocks, so that would cause a permanent
memory leak.
Shawn Hargreaves.
- Raw text -