UNIHIVE

Study Hub UNIPORT CSC 283

CSC 283 · Information Systems and File Structures

Record blocking and buffering

Choosing a block size, how buffers let the processor and the device work at the same time, and the trade-offs involved.

Our notes

2 min read

Why block records

Each read or write of a device has a fixed cost (a gap on tape, a seek and rotation on disk) whatever its size. Reading many records per operation spreads that cost: fewer I/O operations, less wasted space, faster batch runs.

Choosing the blocking factor

Bigger blocks mean:

  • fewer gaps and fewer I/O operations (good),
  • but more memory for buffers, more data read when only one record is wanted (bad for direct access), and more lost if a block is damaged.

So sequential files on tape use large blocks; direct files use blocks matched to the disk sector or page size (4 KB is common).

Worked example: I/O count

A file of 60,000 records of 80 bytes.

  • Unblocked: 60,000 reads.
  • Block of 4,000 bytes: blocking factor 4,000 ÷ 80 = 50; reads = 60,000 ÷ 50 = 1,200.

If each read costs about 12 ms on a disk with random placement, that is 720 s against 14.4 s. Stored together sequentially, the blocked file is faster still.

Buffers

A buffer is an area of main memory that holds a block on its way between the device and the program. The program takes logical records one by one from the buffer (deblocking) and the system reads the next block only when the buffer is empty.

Double buffering

With two buffers, the device fills one while the program works on the other; then they swap. Processing and I/O overlap, so a run takes about the longer of the two times instead of their sum.
Example: each block needs 10 ms to read and 6 ms to process. Single buffer: 16 ms per block. Double buffering: about 10 ms per block (the I/O time), a 37.5% saving.

Buffering today

Operating systems and databases keep large buffer pools (caches) of recent blocks in memory, read ahead when they detect sequential access, and write changed blocks back later (write-back). The same principle: avoid waiting for the device.

Exams usually ask

  • Explain record blocking and the factors in choosing block size.
  • Explain buffering and double buffering with a timing example.
  • Calculate the number of I/O operations for blocked and unblocked files.

Common mistake

Thinking a bigger block is always better. For direct access to single records, a huge block wastes time reading records nobody asked for.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All CSC 283 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.