Using Keyloop Functions Efficiently

Note: This section applies equally to all operating systems, but is especially important to remember when writing Vermont Views applications for UNIX, POSIX and VMS systems.

Vermont Views allows you to install a keyloop function, which is called repeatedly while your program is waiting for a keystroke. This is useful for such tasks as maintaining the current time on the screen. Care should be taken, however, when writing a keyloop function for a multi-user, multi-tasking operating system.

Whenever Vermont Views is waiting for input and there is a keyloop function installed, the system checks for keyboard input, and if there is none, invokes the keyloop function and then checks for input again. If the loop simply performs some task and returns, it places great demands on the CPU. This is sometimes acceptable or even desirable. For those situations in which it is not desirable, your keyloop function should contain code to allow your process to go to sleep briefly. The operating system can then spend time on other tasks.

For portable code, use the Vermont Views function time_delay(), which can delay the program for hundredths of a second if supported on your system. Note that on most UNIX systems, the minimum pause is one second, and time_delay() rounds down the number of hundredths of a second it is passed in this case. You may, therefore, get no pausing during keyloop processing if you specify a small delay in your call to time_delay().


Home Contents Previous Next