Input output
什么是IO,看看维基百科Input/output的解释吧。
wikipedia Input/output
In computing, input/output or I/O (or, informally, io or IO) is the communication between an information processing system, such as a computer, and the outside world, possibly a human or another information processing system. Inputs are the signals or data received by the system and outputs are the signals or data sent from it. The term can also be used as part of an action; to "perform I/O" is to perform an input or output operation.
I/O devices are the pieces of hardware used by a human (or other system) to communicate with a computer. For instance, a keyboard or computer mouse is an input device for a computer, while monitors and printers are output devices. Devices for communication between computers, such as modems and network cards, typically perform both input and output operations.
In computer architecture, the combination of the CPU and main memory, to which the CPU can read or write directly using individual instructions, is considered the brain of a computer. Any transfer of information to or from the CPU/memory combo, for example by reading data from a disk drive, is considered I/O. The CPU and its supporting circuitry may provide memory-mapped I/O that is used in low-level computer programming, such as in the implementation of device drivers, or may provide access to I/O channels. An I/O algorithm is one designed to exploit locality and perform efficiently when exchanging data with a secondary storage device, such as a disk drive.
NOTE: 这就是我们平时所说的IO。
Interface
Higher-level implementation
Higher-level operating system and programming facilities employ separate, more abstract I/O concepts and primitives. For example, most operating systems provide application programs with the concept of files. The C and C++ programming languages, and operating systems in the Unix family, traditionally abstract files and devices as streams, which can be read or written, or sometimes both. The C standard library provides functions for manipulating streams for input and output.
NOTE: 抽象为stream是非常重要,下篇会对此进行详细描述。
An alternative to special primitive functions is the I/O monad, which permits programs to just describe I/O, and the actions are carried out outside the program. This is notable because the I/O functions would introduce side-effects to any programming language, but this allows purely functional programming to be practical.
IO可以看做是data exchange
本节标题的含义是IO可以看做是一种data exchange,即双方**交换数据**,关于data exchange,参见:
wikipedia Data exchange
IO可以看做是一种通信
IO也可以看做是一种通信,因此,双方需要约定好协议。
IO mechanism
本节总结IO的原理,下面是一些素材:
stackoverflow What are the advantages of memory-mapped files? # A
if you use a system call (e.g. Linux's
pread()
) then that typically involves the kernel copying the data from its own buffers into user space. This extra copying not only takes time, but decreases the effectiveness of the CPU's caches by accessing this extra copy of the data.
UNP 6.1 I/O Multiplexing: The select
and poll
Functions¶c
As we show in all the examples in this section, there are normally two distinct phases for an input operation:
1、Waiting for the data to be ready
NOTE:
等待数据就绪
2、Copying the data from the kernel to the process
NOTE: 将数据从kernel拷贝到用户态