ETI windows

The routines wnoutrefresh and doupdate

If you recall from the earlier discussion about refresh, we said that it sends the output from stdscr to the terminal screen. We also said that it was a macro that expands to wrefresh(stdscr) (see ``What every ETI program needs'' and ``More about refresh and windows'').

The wrefresh routine is used to send the contents of a window (stdscr or one that you create) to a screen; it calls the routines wnoutrefresh and doupdate. Similarly, prefresh sends the contents of a pad to a screen by calling pnoutrefresh and doupdate.

Using wnoutrefresh--or pnoutrefresh (this discussion will be limited to the former routine for simplicity)--and doupdate, you can update terminal screens more efficiently than using wrefresh by itself. wrefresh works by first calling wnoutrefresh, which copies the named window to a data structure referred to as the virtual screen. The virtual screen contains what a program intends to display at a terminal. After calling wnoutrefresh, wrefresh then calls doupdate, which compares the virtual screen to the physical screen and does the actual update. If you want to output several windows at once, calling wrefresh will result in alternating calls to wnoutrefresh and doupdate, causing several bursts of output to a screen. However, by calling wnoutrefresh for each window and then doupdate only once, you can minimize the total number of characters transmitted and the processor time used. ``Using wnoutrefresh and doupdate'' shows a sample program that uses only one doupdate.

   #include <ocurses.h>

main() { WINDOW *w1, *w2;

initscr(); w1 = newwin(2,6,0,3); w2 = newwin(1,4,5,4); waddstr(w1, "Bulls"); wnoutrefresh(w1); waddstr(w2, "Eye"); wnoutrefresh(w2); doupdate(); endwin(); }

Using wnoutrefresh and doupdate

Notice from the sample that you declare a new window at the beginning of an ETI program. The lines

   w1 = newwin(2,6,0,3);
   w2 = newwin(1,4,5,4);
declare two windows named w1 and w2 with the routine newwin according to certain specifications. newwin is discussed in more detail below.

``Relationship between a window and terminal screen (sheet 1 of 3)'', ``Relationship between a window and terminal screen (sheet 2 of 3)'', and ``Relationship between a window and terminal screen (sheet 3 of 3)'' illustrate the effect of wnoutrefresh and doupdate on these two windows, the virtual screen, and the physical screen.

Relationship between a window and terminal screen (sheet 1 of 3)

Relationship between a window and terminal screen (sheet 2 of 3)

Relationship between a window and terminal screen (sheet 3 of 3)

Next topic: New windows
Previous topic: Output and input

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004