当前位置:网站首页>file IO-buffer

file IO-buffer

2022-08-10 22:30:00 dry rice white

How to understand input and output

1. From the perspective of the document

 

2. From the perspective of memory

When we write programs, we think about problems from the perspective of memory.

If we are manipulating the file, input into the file, the expression obtained from the file is more accurate.

The relationship between standard C library IO and Linux system IO

1. The bottom layer of the C library function actually calls the Linux system function

2.C library IO has buffer, Linux system function has no buffer

Benefits of having a buffer:

Improve efficiency

For example, there are 100 eggs that need to be transported from point A to point B. If there is no buffer, they can only be transported one by one. If there is a buffer, then it is equivalent to having a box, assuming that the box canLoad 20 eggs. When the box is full or flushed or there are no more eggs left in area A, the eggs will be delivered to point B through the box.

Three times to refresh the memory buffer

1. Active refresh fflush

2. The buffer is full

3. Close the file normally close return return exit

File pointer FILE

We know that C language operation files are carried out through FILE, and FILE is a structure.Among them, there are three most important members

1. The corresponding disk file can be indexed through the file descriptor

2. The read and write position in the file can be determined by the file read and write pointer

3. I/O buffer (same as the function mentioned above, reduce the number of disk reads and writes to improve efficiency)

Why is disk read and write slow

In the process of learning, we often encounter reducing disk read and write operations to improve efficiency, because disk operations are relatively slow.This is a hardware defect, Most of the disks are mechanical disks, the read seek time and write seek time are both millisecond level, while memory belongs to electronic equipment, and read and write is nanosecond level.1ms = 10^7ns

原网站

版权声明
本文为[dry rice white]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208102148593213.html