Question

Describe when a programmer should manually flush a buffer and when they shouldnt. BIVA-AI E E71 x ! - V A T 12pt Paragraph I
0 0
Add a comment Improve this question Transcribed image text
Answer #1

What does buffer flush means ?

A buffer flush is the transfer of computer data from a temporary storage area to the computer’s permanent memory. For instance if we make any changes in a file, the changes we see on one computer screen are stored temporarily in a buffer.
Usually a temporary file come into existence when we open any word document, and automatically destroyed when we close our main file. Thus when we save our work, the changes that we’ve made to our document since the last time we saved it are flushed from the buffer to permanent storage on the hard disk.

Due to formatted I/O buffers issue,programmer should flush the buffer

This section describes flushing issues that are related to formatted I/O buffers. The descriptions apply to all buffered read and buffered write operations. For example, the viPrintf() description applies equally to other buffered write operations (viVPrintf() and viBufWrite()). Similarly, the viScanf() description applies to other buffered read operations (viVScanf() and viBufRead()).

Flushing a write buffer immediately sends any queued data to the device. Flushing a read buffer discards the data in the read buffer. An empty read buffer guarantees that the next call to viScanf(), viBufRead(), or a related operation reads data directly from the device rather than from queued data residing in the read buffer.

The easiest way to flush the buffers is with an explicit call to viFlush(). This operation can actually flush the buffers in two ways. The simpler way uses discard flags. These flags tell the driver to discard the contents of the buffers without performing any I/O to the device. For example,

status = viFlush(instr, VI_READ_BUF_DISCARD);

However, the flush operation can also complete the current I/O before flushing the buffer. For a write buffer, this simply means to send the rest of the buffer to the device. However, for a read buffer, the process is more involved. Because you could be in the middle of a read from the device (that is, the device still has information to send), it is possible to have the driver check the buffer for an EOS or END bit/EOI signal. If such a value exists in the buffer, the contents of the buffer are discarded. However, if the driver can find no such value, it begins reading from the device until it detects the end of the communication and then discards the data. This process keeps the program and device in synchronization with each other.

If, on the other hand, you are doing a bulk operation, you typically should not flush buffers explicitly; the operating system will batch the operations for efficiency and only flush partially-full buffers when you close the output file.

Add a comment
Know the answer?
Add Answer to:
Describe when a programmer should manually flush a buffer and when they shouldn't. BIVA-AI E E71...
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
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