Recall & Review
beginner
What is buffering in the context of input/output (I/O) operations?
Buffering is a technique where data is temporarily stored in a memory area called a buffer before being sent to its destination. This helps improve efficiency by reducing the number of I/O operations.
Click to reveal answer
beginner
What does flushing mean in file or stream operations?
Flushing means forcing the data in the buffer to be written out immediately to the destination, such as a file or the screen, instead of waiting for the buffer to fill up.
Click to reveal answer
beginner
Why is buffering useful when writing data to a file?
Buffering reduces the number of write operations by collecting data in memory first. This makes writing faster and more efficient because writing to disk is slower than writing to memory.
Click to reveal answer
beginner
How can you flush a file or stream in Python?
You can call the flush() method on a file or stream object, like file.flush(), to force the buffered data to be written immediately.
Click to reveal answer
beginner
What happens if you don't flush the buffer before a program ends?
If the buffer is not flushed, some data may remain in memory and not be saved or displayed, causing loss of data or incomplete output.
Click to reveal answer
What is the main purpose of buffering in I/O operations?
✗ Incorrect
Buffering collects data in memory to reduce slow I/O operations by writing larger chunks at once.
In Python, which method forces buffered data to be written out immediately?
✗ Incorrect
The flush() method forces the buffer to write its data immediately.
What could happen if you forget to flush a buffer before a program ends?
✗ Incorrect
Unflushed data remains in the buffer and may be lost if not written out.
Which of these is NOT a benefit of buffering?
✗ Incorrect
Buffering delays writing until the buffer fills or flush is called; immediate writing is opposite to buffering.
When is flushing automatically done by Python?
✗ Incorrect
Python flushes buffers automatically when full or when the file/stream is closed.
Explain buffering and flushing in your own words and why they matter in programming.
Think about how writing to a file or screen works behind the scenes.
You got /4 concepts.
Describe a real-life example that helps you understand why buffering and flushing are useful.
Consider how you might collect mail before delivering it all at once.
You got /3 concepts.