Console dual-buffering technology, console Buffering

Source: Internet
Author: User

Console dual-buffering technology, console Buffering
Introduction

The dual-buffer technology is mainly used in plotting. However, leveraging the principles of the dual-buffer technology, you can experience the advantages of your console programs better, such as the console game you have compiled, you often need to constantly refresh the screen, which may cause very serious problems-screen flashing! This greatly reduces the user experience (although there are no users, it does not prevent us from pursuing perfection ~), Double Buffering can eliminate this flicker.

 

Technical Principle of Double Buffering on the console:

Background: what you see on the black interface is displayed in the "screen buffer". The buffer we can see is called "Current (active) screen buffer ", we can create other buffers or operate on them, but they are invisible.

Principles:

Create a screen buffer (invisible at this time)

Write the content you want to display once in the newly created screen buffer.

Set the buffer to the current buffer (visible)

----> Why is the problem solved?

Explanation: Suppose you print a series of 11111111111111111111111111111111111111111111111111111 messages on the screen. If you use loop printf ("1"), the actual situation is that the output is 1, 11, and then 111 first on the screen ,, and so on, we can see the write process. In this process, we will feel flashes. If so many 1 s are displayed, there will be no flashes, the write process of the dual buffer bar is placed in the invisible screen buffer. The flash problem is solved when it is displayed at one time.

Specific implementation:

--------------------------------- Create a screen buffer --------------------------------------

 

------------------------------------ Option: Hide the cursor ---------------------------------------

 

------------------------------- Write what you want to display ---------------------------------------

WriteConsole (hNewConsole, "Here is the string", strlen (p), NULL, NULL );

------------------------------------------ Activate --------------------------------------------------

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.