Io operation in Golang and the expression of reading and writing pointer movement in it

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.
Figure 1



Figure 2


From the comparison of Figure 1 and Figure 2 can be seen, figure 2 is less than the 15th line of the read operation, and then the result of the figure 2 code run, is all the Hello WORLDABCDEFG, the code of Figure 1 only from read after the ABCDEFG.

What is the reason?

Read-write pointers in which mischief! Each read and write operation starts at the pointer position.

In Figure 1, after the first read, the read-write pointer has run to the place of Hello Word, not in 0, so the second read results from this non-0 pointer after the beginning of reading, so the result is only the back of the ABCDEFG.

In Figure 2, the read operation is not performed at first, so the reading and writing pointers remain at 0, so the next read starts at 0. The result is the full Hello WORLDABCDEFG.



Figure 3

As you can see from Figure 3, using buf.string () This way you can see that there is no movement of the read pointer.



Figure 4

As you can see from Figure 4, the first print is Hello world and not Hello Worldhello world, because there is a read operation. The read pointer is moved.

The second time you print out Hello Worldhello world is because it was written again. Indicates that the Wtire write operation does not move the pointer, and read read does not move the pointer.



Figure 5

From the ReadByte () and Unreadbyte () operations in Figure 5, it is more clear to see the movement of the read and write pointers.

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.