The difference between standard I/O and file I/O

1. Definition of standard I/O and file I/O

Standard I/O : Standard I/O is a series of functions defined in ANSI C for I/O operations, with a certain degree of portability. The standard I/O library handles many details. For example, cache allocation, I/O with optimized length, etc. Standard I/O provides three types of cache

  1. Full cache: When the standard I/O cache is filled, the actual I/O operation is performed. Ordinary files on the disk are fully buffered by default when opened with standard I/O
  2. Line cache: When a newline character is encountered in input or output, the standard I/O library performs I/O operations. Standard input/output stream is a typical example of using line buffering
  3. Without cache: I/O operations are not buffered, that is, the actual file will be operated immediately when reading and writing the stream. For example, the standard error stream stderr, so that the error information can be immediately displayed on the terminal

File I/O : File I/O is called unbuffered I/O. Without caching means that every read and write calls a system call in the kernel. Also known as low-level I/O

Two, the difference between the two

Standard I/O File I/O
With buffer Unbuffered
Advanced disk I/O, follow ANSI C standards Low-level disk I/O, follow POSIX related standards
When reading and writing files, read and write the buffer first. Visit the actual file when necessary, thereby reducing the number of system calls When reading and writing files, relevant system calls are executed every time. Can directly read and write actual files, but increases system overhead
Use FILE (stream) to represent an open file, usually only ordinary files can be accessed Use a file descriptor to represent an open file, which can access ordinary files, device files, pipe files, etc.

POSIX: Portable Operation System Interface

Guess you like

Origin blog.csdn.net/Chuangke_Andy/article/details/108262466