This document discusses different file structures for organizing records in files. It describes how fields can be organized into records and different ways of structuring records in a file, including:
- Fixed-length records with all records having the same predictable length
- Variable-length records where records can be different lengths
- Using length indicators, delimiters, or secondary index files to identify the start and end of records
The key points are that files can be organized at the field and record level, and different structures like fixed vs variable length, length indicators, and delimiters can be used to maintain the logical relationships between fields within records and between records in the file.
This document discusses different file structures for organizing records in files. It describes how fields can be organized into records and different ways of structuring records in a file, including:
- Fixed-length records with all records having the same predictable length
- Variable-length records where records can be different lengths
- Using length indicators, delimiters, or secondary index files to identify the start and end of records
The key points are that files can be organized at the field and record level, and different structures like fixed vs variable length, length indicators, and delimiters can be used to maintain the logical relationships between fields within records and between records in the file.
This document discusses different file structures for organizing records in files. It describes how fields can be organized into records and different ways of structuring records in a file, including:
- Fixed-length records with all records having the same predictable length
- Variable-length records where records can be different lengths
- Using length indicators, delimiters, or secondary index files to identify the start and end of records
The key points are that files can be organized at the field and record level, and different structures like fixed vs variable length, length indicators, and delimiters can be used to maintain the logical relationships between fields within records and between records in the file.
The smallest logical unit of data is the field which
contains a single data value. Fields are organized into aggregates, either as many copies of a single field (an array) or as a list of different fields (a record). When a record is stored in memory, we refer to it as an object and refer to its fields as members. In this lecture, we will investigate the different ways on how objects can be represented as records in files. Stream File
Mary Ames Alan Mason
123 Maple 90 Eastgate Stillwater, OK 74075 Ada, OK 74820 Stream of bytes is a term describing the lowest-level view of a file. In Stream Files, the information is written as a stream of bytes containing no added information: AmesMary123 MapleStillwaterOK74075MasonAlan90 EastgateAdaOK74820 Problem: There is no way to get the information back in the organized record format. Field Structures
There are many ways of adding structure to files to
maintain the identity of fields:
Force the field into a predictable length
Ames Mary 123 Maple Stillwate OK 74075 Mason Alan 90 Eastgate Ada OK 74820 Begin each field with a length indicator 04Ames04Mary09123 Maple10Stillwate02OK0574075 05Mason04Alan1190 Eastgate03Ada02OK0574820 Field Structures
There are many ways of adding structure to files to
maintain the identity of fields:
Place a delimiter at the end of each field to separate it
from the next field. Ames|Mary|123 Maple|Stillwate|OK|74075| Mason|Alan|90 Eastgate|Ada|OK|74820|
Delimiter is one or more characters used to separate
fields and records in a file. Field Structures
Use a keyword = value expression to identify each
field and its content. last=Ames|first=Mary|address=123 Maple|city=Stillwate|state=OK|zip=740 75| Reading a Stream of Fields
A Program can easily Last Name: Ames
read a stream of fields First Name: Mary and output ===> Address: 123 Maple City: Stillwater State: OK This time, we do Zip Code: 74075 preserve the notion of Last Name: Mason fields, but something is First Name: Alan Address: 90 Eastgate missing: Rather than a City: Ada stream of fields, these State: OK should be two records Zip Code: 74820 Record Structure
A record can be defined as a set of fields that belong
together when the file is viewed in terms of a higher level of organization. Like the notion of a field, a record is another conceptual tool which needs not exist in the file in any physical sense. Yet, they are an important logical notion included in the files structure. Record Structure
Methods for organizing the records of a file include:
Fixed-length record is a file organization in which all
records have the same length. 1. Requiring that the records be a predictable number of bytes in length. a) Fixed-length records with fixed-length fields. b) Fixed-length records with variable-length fields. Record Structure
Methods for organizing the records of a file include:
Variable-length records is a file organization in which the records have no predetermined length. 2. Requiring that the records be a predictable number of fields in length. 3. Beginning each record with a length indicator consisting of a count of the number of bytes that the record contains. 4. Using a second file to keep track of the beginning byte address for each record. (Index file) 5. Placing a delimiter at the end of each record to separate it from the next record. Record Structures that Use a Length Indicator
Implementation:
* Writing the variable-length records to the file
* Representing the record length * Reading the variable-length record from the file. The End