From: Sergio Masci (sergio@xcprod.com)
Date: Fri 28 Dec 2001 - 15:09:24 IST
> > I have a question about cpu usage.. > > in main loop I use; > > void mainloop(void) > > { > > int key; > > while ( (key = vga_getkey()) != 27) > > { > > } > > } > > but like this, cpu usage raises up to %90 > > vga_getkey() is non-blocking, so it's going to keep looping until a value > of 27 is received. You might consider inserting a delay -- maybe something > as small as usleep(200000) -- which will slow down your process, but not > so much as to impede input. > > I believe(?) that even if input is received during the pause, it will go > into a buffer and vga_getkey() will read from that, so nothing will be > lost. Matan? Sergio? > Yes as Jay suggests, putting in a usleep will make all the difference. The length of time you want to sleep for will depend on exactly what it is you are doing after a key press. I have not experienced any data loss using vga_getkey() and I would be surprised if it is not buffered. > Finally, I assume you know about the vlocking call vga_getch(), and would > use that if possible. > I cannot comment on vga_getch, since I've been using vga_getkey for many years now and haven't touched vga_getch for a very long time, but if it is blocking it might sove a lot of your problems if all you are doing is waiting for a specific key at a specific point in your code. Regards Sergio ------------------------------------------------------------------ Unsubscribe: To: listbot@svgalib.org Body: unsubscribe linux-svgalib
This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:24 IST