Variable length records

One or more of the fields can be of differing lengths in each record.

Advantages:

  • the records will be smaller and will need less storage space
  • the records will load or save faster
  • the file will be faster to transmit down a network

Disadvantages:

  • The computer will be unable to determine where each record starts so processing the records will be slower.

Example : A file that needs to be downloaded from a network site. Eg. An Internet database.

 

 

Storage method 1.

When the record is stored, each field has a field terminator byte stored at the end of it, and there is often a record terminator at the end of the whole record.

The first record of the example would be stored as .....

9 2 0 1 3 * J O N E S * S i d n e y * 1
2 * B * 2 3 / 0 4 / 7 8 %              
                                       
  • * is a field terminator

  • % is a record terminator

This record requires 33 bytes of storage.....but each record will be a different size.

 

 

Storage method 2.

Each field starts with a byte showing the length of the field. The whole record starts with a byte giving the size of the record. The first record of the example would be stored as....

34 5 9 2 0 1 3 5 J O N E S 6 S i d n e y
2 1 2 1 B 8 2 3 / 0 4 / 7 8            
                                       

This record requires 34 bytes of storage....but again, each record would be a different size.