Variable Length Storage with Fixed Maximum

The storage of variable-length strings in memory cells with fixed lengths can be done in two general ways:
  1. One can use a marker, such as two dollar signs ($$), to signal the end of the string.
  2. One can list the length of the string- as an additional item in the pointer array, for example.
Program printing two integers in increasing order:
  • READ *, J, K
  • IF (J.LE.K) THEN
  • PRINT *, J, K
  • ELSE
  • PRINT *, K, J
  • ENDIF
  • STOP
  • END

Second method

One might be tempted to store strings one after another by using some separation marker, such as the two dollar signs ($$) in first figure, or by using a pointer array giving the location of the strings, as shown in second figure. These ways of storing will obviously save and are sometimes used in secondary memory when records are relatively permanent and require little change. However, such methods of storage are usually inefficient when the strings and their lengths are frequently being changed.
Powered by Blogger.