Why is the buffer in the input and output stream?

zhaozj2021-02-11  231

This problem I really seriously think about the C basic IO class (, what you eat when you first go to school, now start to work). I believe that many people are very clear about this question, but I also believe that many people have not considered this problem as I am. Now I want to publish my understanding, welcome everyone to criticize.

I want to explain with an example. For example, I want to output an article on a character sequence to the computer monitor screen, then my program memory as a data source, the display driver as a data target, if the data source is sent directly Data of the data. The data target gets the first character and displays it. Then read the next character from the port, but it is not possible to ensure that the data source is sent to the port exactly the second character (perhaps the third, while the second has been sent when the data target is displayed). In this case, it cannot guarantee that the output data can be completely accepted and processed by the data objective.

In order to solve this problem, we need to place a region where the full data content saves full data content in the middle of the data source and the data target, that is, DangDangDangDang ---- "Buffer". In this case, the data source may not consider which data is processing which data is being processed, as long as the data is output to the buffer, the data target may also not consider the transmission frequency of the data source, just remove the next data from the buffer. This ensures the integrity of the data transmission, and also improves the efficiency of the program.

I understand it? :)

转载请注明原文地址:https://www.9cbs.com/read-4382.html

New Post(0)