Question

Consider one of the following pairs of scenarios. Buffered vs. non-buffered input 1. In your initial...

Consider one of the following pairs of scenarios. Buffered vs. non-buffered input 1. In your initial message, include the following information: Technical differences (e.g., mode of operation, method of implementation) in one versus the other 2. Unique challenges in using each of them in an application 3. Potential benefits and drawbacks of each 4. Finally, select a scenario in which you might need to choose between the types I/O.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In general, buffered I/O is faster but can be less reliable under certain circumstances.

Unbuffered I/O involves reading or writing data one element at a time: If the data stream is character-based, like a file on disk in a UNIX system, that means reading or writing the data character-by-character. Because the overhead involved in each I/O request is so great (due to the physical nature of the underlying device) and the number of requests is so high, this tends to be very slow. However, because all data accesses are resolved by the I/O device immediately, there's normally no way for the data "seen" by the process to ever disagree with the data actually in storage.

Buffered I/O involves reading or writing data in chunks: If a request to read a single character is made the system will actually read, say, a thousand characters from the device into a buffer in memory, then return just the first character from the buffer to the calling routine. Subsequent requests can be fulfilled entirely from the buffer (until it is depleted), which as it exists in memory can be accessed many times faster than can the device itself.

Buffered writes happen in a similar manner: Data written by a process is first accumulated in a buffer in memory until the buffer is full (or a time limit elapses), at which point the entire buffer is written to the device at once. Again, this reduces the number of real I/O operations involved and makes the system appear much faster.

Note that some devices lend themselves to buffered I/O naturally. This is true for instance of mechanical hard drives, which not only suffer from extremely high latency compared to regular memory but also permit data to be accessed only in multi-kilobyte chunks anyway.

So is it always better to use buffered I/O? Not necessarily. Buffered reads can yield incorrect results if the data in the buffer is stale, as can happen when one process modifies the data on the storage device but another continues to work with its (now out-of-date) copy in memory. Also, buffering writes can result in data loss, if for instance power to the computer is interrupted between data being written to the buffer in memory and the buffer's contents being output (flushed) to the device. Techniques are available to address both these scenarios.

You want unbuffered output when you already have large sequence of bytes ready to write to disk, and want to avoid an extra copy into a second buffer in the middle.

Buffered output streams will accumulate write results into an intermediate buffer, sending it to the OS file system only when enough data has accumulated (or flush() is requested). This reduces the number of file system calls. Since file system calls can be expensive on most platforms (compared to short memcpy), buffered output is a net win when performing a large number of small writes. Unbuffered output is generally better when you already have large buffers to send -- copying to an intermediate buffer will not reduce the number of OS calls further, and introduces additional work.

Unbuffered output has nothing to do with ensuring your data reaches the disk; that functionality is provided by flush(), and works on both buffered and unbuffered streams. Unbuffered IO writes don't guarantee the data has reached the physical disk -- the OS file system is free to hold on to a copy of your data indefinitely, never writing it to disk, if it wants. It is only required to commit it to disk when you invoke flush(). (Note that close() will call flush() on your behalf).

You want unbuffered output whenever you want to ensure that the output has been written before continuing. One example is standard error under a C runtime library - this is usually unbuffered by default. Since errors are (hopefully) infrequent, you want to know about them immediately. On the other hand, standard output is buffered simply because it's assumed there will be far more data going through it.

Another example is a logging library. If your log messages are held within buffers in your process, and your process dumps core, there a very good chance that output will never be written.

In addition, it's not just system calls that are minimized but disk I/O as well. Let's say a program reads a file one byte at a time. With unbuffered input, you will go out to the (relatively very slow) disk for every byte even though it probably has to read in a whole block anyway (the disk hardware itself may have buffers but you're still going out to the disk controller which is going to be slower than in-memory access).By buffering, the whole block is read in to the buffer at once then the individual bytes are delivered to you from the (in-memory, incredibly fast) buffer area.Keep in mind that buffering can take many forms, such as in the following example:

+-------------------+-------------------+
| Process A         | Process B         |
+-------------------+-------------------+
| C runtime library | C runtime library | C RTL buffers
+-------------------+-------------------+
|               OS caches               | Operating system buffers
+---------------------------------------+
|      Disk controller hardware cache   | Disk hardware buffers
+---------------------------------------+
|                   Disk                |
+---------------------------------------+
Add a comment
Know the answer?
Add Answer to:
Consider one of the following pairs of scenarios. Buffered vs. non-buffered input 1. In your initial...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!)....

    CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!). Can be resubmitted up to two times until Session 6 if your first version is submitted by session 3. In this project, you create two classes for tracking students. One class is the Student class that holds student data; the other is the GradeItem class that holds data about grades that students earned in various courses. Note: the next three projects build on this...

  • Please help! Your task is to select an idea, improvement or opportunity that could be applied...

    Please help! Your task is to select an idea, improvement or opportunity that could be applied in a business operation. Describe the business and the project you might initiate. You will need to describe and define the project in context. Explain why such a project would be beneficial. What procedures might you use to ensure that the project was sponsored and supported by the organisation? Define the project, write a project narrative and develop a project plan, including the processes...

  • Please help! Your task is to select an idea, improvement or opportunity that could be applied...

    Please help! Your task is to select an idea, improvement or opportunity that could be applied in a business operation. Describe the business and the project you might initiate. You will need to describe and define the project in context. Explain why such a project would be beneficial. What procedures might you use to ensure that the project was sponsored and supported by the organisation? Define the project, write a project narrative and develop a project plan, including the processes...

  • Discussion questions 1. What is the link between internal marketing and service quality in the ai...

    Discussion questions 1. What is the link between internal marketing and service quality in the airline industry? 2. What internal marketing programmes could British Airways put into place to avoid further internal unrest? What potential is there to extend auch programmes to external partners? 3. What challenges may BA face in implementing an internal marketing programme to deliver value to its customers? (1981)ǐn the context ofbank marketing ths theme has bon pururd by other, nashri oriented towards the identification of...

  • QUESTION 1: Why must project manager should have good technical skills but also good management skills?...

    QUESTION 1: Why must project manager should have good technical skills but also good management skills? QUESTION 2: **Communication and Communicator are related" This quote from the text suppose that the communication process is lead by the spokeperson. Do you think is it a gift" to be a good communicator or a skill to improve ( use example of your knowledge to answer)? QUESTION 3: Look at the text paragraph yellow highlighted, and do you think that in today's world...

  • 1. According to the paper, what does lactate dehydrogenase (LDH) do and what does it allow...

    1. According to the paper, what does lactate dehydrogenase (LDH) do and what does it allow to happen within the myofiber? (5 points) 2. According to the paper, what is the major disadvantage of relying on glycolysis during high-intensity exercise? (5 points) 3. Using Figure 1 in the paper, briefly describe the different sources of ATP production at 50% versus 90% AND explain whether you believe this depiction of ATP production applies to a Type IIX myofiber in a human....

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • Read the Article posted below, then answer the following questions: Mergers & acquisitions are a major...

    Read the Article posted below, then answer the following questions: Mergers & acquisitions are a major form of corporate diversification strategy, identify and discuss the top three reasons why most (50-60%) of acquisitions fail to create shareholder value. What are the five major components of “CEMEX Way” and why has this approach been so successful in post-acquisition integration? In your opinion, what can other companies learn from the “CEMEX Way” as a benchmark for acquisition management? Article: CEMEX: Globalization "The...

  • summarizr the followung info and write them in your own words and break them into different...

    summarizr the followung info and write them in your own words and break them into different key points.   6.5 Metering Chamber: 6.5.1 The minimum size of the metering box is governed by the metering area required to obtain a representative test area for the specimen (see 7.2) and for maintenance of reasonable test accuracy. For example, for specimens incorporating air spaces or stud spaces, the metering area shall span an integral number of spaces (see 5.5). The depth of...

  • A. Issues [1] In addition to damages for one year's notice period, can a trial judge...

    A. Issues [1] In addition to damages for one year's notice period, can a trial judge award significant damages for the mere fact of an employee's dismissal, or for the stigma that that dismissal brings? Or for the employer thereafter competing with the ex-employee for the clients, before the ex-employee has got a new job? B. Basic Facts [2] This is an appeal from 2009 ABQB 591 (CanLII), 473 A.R. 254. [3] Usually a judgment recites facts before law. But...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT