Exam 1, Question 4 Solution

Written by Sanghwan Lee

Standard I/O (20 pts.)

Note : The question 4 is about the ANSI C Standard I/O library, not about genera l I/O buffering.

A.

This is an example of both horizontal abstraction and vertical abstraction. By using the same high level function calls, the program can be executed on any system for which an ANSI-C-compilant compiler exists. => horizonrtal abstraction .
And by using the same high level function calls, the low level details of the un derlying hardware will be hided to the application programmer. => vertical abstr action.

B. (from H, G & S, p 274)

The standard I/O Library's buffering mechanism ensures that data is always read from or written to an external file in standard-size cunks.
An output routine from the Standard I/O Library will fille the buffer character by character. If the buffer becomes full, an internal Standard I/O routine will write its contents to the file using the write system call. This remains invisib le to the user program.
An input routine will pull data out of the buffer associated with the FILE struc ture. If the buffer is emptied, another buffer-full will be read from the file u sing the read system call. Again this remains invisible to the user program.

Other Answers from students. (it's from Nutt 104)
Buffering input and output is a technique by which the device manager can keep slower I/O devices busy during times when a process is not requiring I/O operation.
Input buffering is accomplished by having the input device reading information into the primary memory before the process requests it.
Output buffering is accomplished by saving information into memory and then writing it to the device while the process continues execution.

C.
Note : This question is about the benefits of I/O buffering done by Standard I/O library, not about the benefits of Standard I/O library itself nor about the benefits of I/O buffering in general.
It is fast since memory access is much faster than disk access.
It minimizes the disk access because it reads or writes a chunk of data at a time.

Other Answers from students.

Overlapping processes. And I/O operation can be overlapped with an execution in another process if data is buffered.
Overlap a process's use of the CPU and its devices.

D.
The output buffer has some data and has not been written to disk yet. If the system crashes, then the data in the buffer will be lost.

Other Answers from students.

- After write some data to output buffer, and if it reads it again, the data will be old data.
- Sometimes CPU read past the buffer, then the data read would be old or no data .