[prev] 51 [next]

Structured Data (cont)

Files of records can be produced by
  • either, write()ing chunks of bytes from struct objects
  • or, printing formatted text representation of struct data
The latter approach is a form of serialisation

For the write() approach:

  • no need to worry about formatting issues
  • writes entire structure, even if string buffers half empty
  • can lseek() to ith struct via i*sizeof(StructType)
For the printing approach:
  • produces files that are human-readable
  • only uses as many bytes as required from string buffers
  • can access structures only sequentially (unless using padding)