|Top Previous Next|
When text or graphics are written to the Console Window they aren't necessarily displayed immediately. The display is only refreshed under certain circumstances. Controlling the refresh can speed up operations by many times. The Console Window is refreshed under the following circumstances:
1. Periodic Refresh. The Console Window is automatically refreshed periodically by a Windows timer. To simulate a video card, the console window is normally refreshed 30 times per second. Since a Window timer event is received by a program's main thread, the console won't actually be refreshed unless the main thread is idle. This occurs when a program is waiting for input and other similar circumstances. The Periodic Refresh is designed to catch changes to the screen that aren't refreshed directly by an output routine.
2. Output Refresh. The Console is also refreshed every time an output operation of any kind is performed. This applies to text output and any graphics operation such as displaying bitmaps or drawing lines.
3. Exiting a Program. The Console is refreshed whenever a program exits. This is designed to display any changes that may have occurred just before the program shuts down.
4. Debugging and Single Stepping. The Console is refreshed every time a line of code is executed in the Debugger. It is also refreshed whenever a breakpoint is encountered.
Controlling Refresh. Preventing screen refreshes can speed up operations by 10s or 100s of times. For example, if you were outputting hundreds of individual characters with the ChOut intrinsic, the screen will be refreshed after every character. Since the screen takes about 300 microseconds to refresh on a modern Pentium computer, filling the screen with characters could take up to a half-second, too slow for any sort of rapid animation.
The EnableRefresh (135) intrinsic can be used to enable or disable all refreshes. This allows you to disable refreshes before you do any write-intensive operation and enable them when you are finished, which speeds up the display. Note: If you disable refreshes, even normal Windows refreshes are blocked, so be sure to turn them back on when you are done.