Optimal disk and memory records

If you read and write a record type to disk and you want the most efficient use of disk space and the most efficient use of memory you may needto use two records. One to write the data to disk and another to use while loaded into memory. An example of this would be if you had a numeric field that could only contain a value between 0 and 127. This value can fit within a single byte integer type. INTEGER8 for Modula-2 and Byte_Integer for Ada95. Assuming 32-bit code an Integer type takes four bytes. This is a savings of three bytes. The Integer type is moreefficient in code generation than single byte integers, so although more memory isused you may want to use the Integer type when loaded into memory. A very simpleway of handling this, and encapsulating the application code from the disk format is as follows.

Define two records. One for memory use. One for disk use.

Define two procedures. One to write the record type to disk and another to read.

Only these procedures understand and use the disk format record type. The rest of the program uses the memory format.

All access to the disk for these records goes through these two procedures.

By doing this you have also made your code more portable. Porting to other compilers and/or other operating systems becomes easier. You are more portable because