UNIHIVE

Study Hub UNIPORT CSC 283

CSC 283 · Information Systems and File Structures

Records: fixed, variable and blocked

How records are laid out, fixed and variable length records, record keys and the difference between logical and physical records.

Our notes

2 min read

Fixed length records

Every record has the same length L. The position of record n (counting from 0) is simply n × L from the start of the file, so a program can jump straight to it. Simple and fast, but space is wasted when fields are not full.

Variable length records

Records differ in length because:

  • fields have variable length (names, addresses), or
  • the number of fields varies (a student may have 6 or 12 course results: a repeating group), or
  • optional fields are present only sometimes.

Ways to mark them:

  1. A length count at the start of each record.
  2. An end-of-record marker (a special character, such as a newline in a text file).
  3. A fixed part plus a variable part with a count of repeats.

Variable records save space but cannot be found by simple arithmetic, and a record that grows during an update may not fit back in its old place.

Logical and physical records

  • Logical record: the record as the program sees it (one student).
  • Physical record (block): the unit actually read or written by the device in one operation. A block usually holds several logical records.
  • Blocking factor = number of logical records per block.

Worked example: records per block

Blocks of 4,096 bytes; fixed records of 72 bytes.

  • Blocking factor = floor(4,096 ÷ 72) = 56 records per block (56 × 72 = 4,032 bytes used; 64 bytes left over).
  • For 25,000 records: blocks needed = ceiling(25,000 ÷ 56) = 447 blocks.

Records do not usually span two blocks (unspanned), so the leftover 64 bytes in each block are wasted.

Spanned and unspanned records

  • Unspanned: a record must fit inside one block; some space is lost at the end of each block.
  • Spanned: a record may continue into the next block; no waste, but reading one record can need two block reads. Needed when records are larger than a block.

Choosing keys

A good primary key is unique, never changes, short and has no meaning that may become false (a matric number with the year in it is fine because the year it records never changes; a key that includes the department breaks when a student changes department).

Exams usually ask

  • Distinguish logical and physical records; define blocking factor.
  • Give reasons for variable length records and ways of marking them.
  • Calculate blocking factors and the number of blocks.

Common mistake

Dividing the block size by the record size and rounding up. The blocking factor rounds down (you cannot fit part of a record in an unspanned block); the number of blocks rounds up.

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.