Message-ID: <8D53104ECD0CD211AF4000A0C9D60AE34CCD4D@probe-2.acclaim-euro.net> From: Shawn Hargreaves To: djgpp AT delorie DOT com Subject: Re: keyboard handler... Date: Thu, 4 Feb 1999 11:00:54 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1460.8) Content-Type: text/plain Reply-To: djgpp AT delorie DOT com 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.