} Continue different methods for record
} Continue with the company class;
} Use length indicator,
} Use index.
} Buffering records into memory.
Dr. Hussien M. Sharaf 2
Dr. Hussien M. Sharaf 3
} To store the record length just ahead of the record.
Dr. Hussien M. Sharaf 4
4. Length indicator
Record 3 Record 4Record 1 Record 2
1. The field length must not be too long (less than
256 bytes) to be stored in a single byte.
2. Needs more programming effort.
3. Requires at least two disk trips for each record.
210 250 180 190
} Store the byte offset of each record into a list stored in
Dr. Hussien M. Sharaf 5
1. Two files are used: one for the data and another for
20090222 211Record2 n
20090343 62Record3 n
2009393 143Record4 n
Ø The purpose is to read entire record into RAM
then use string operations to split it into fields.
Ø Instead of accessing the disk many times to read
each field, only one disk trip is needed for each
Ø String manipulations done in RAM is much
faster than doing same number of disk trips.
Dr. Hussien M. Sharaf 6
Ø It is another form of string variables.
Ø A stream is built upon a string variable to give
the same functionalities and behavior of file
Ø Since we have done a lot of coding on the basis
of streams then we can make use of our code.
Ø The final target is to do fields splitting in RAM
instead of doing it on disk.
Dr. Hussien M. Sharaf 7
} When overloading operators << and >> it is
better to use ostream and istream which are the
parents of ofstream and ifstream
Dr. Hussien M. Sharaf 8
Ø Continue using the CompanyInfo class:
Read the whole record into a stringstream.
Then pass the stringStream to a method that
extracts each field into its correct data-
member inside the CompanyInfo class.
Dr. Hussien M. Sharaf 10