80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
CS215 - Lec 6 record index
1.
2. } Continue different methods for record
organization.
} Continue with the company class;
} Use length indicator,
} Use index.
} Buffering records into memory.
Dr. Hussien M. Sharaf 2
3. Dr. Hussien M. Sharaf 3
Fixed
length of
bytes
Variable length
Length
indicator
Record
delimiter
Record
index
4. } 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
} Problems:
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
5. } Store the byte offset of each record into a list stored in
another file.
Dr. Hussien M. Sharaf 5
5. Index
} Problems:
1. Two files are used: one for the data and another for
Student_ID offset
20090172 1023Record1
n
n
20090222 211Record2 n
20090343 62Record3 n
2009393 143Record4 n
6. Ø 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
record.
Ø String manipulations done in RAM is much
faster than doing same number of disk trips.
Dr. Hussien M. Sharaf 6
7. Ø It is another form of string variables.
Ø A stream is built upon a string variable to give
the same functionalities and behavior of file
streams.
Ø 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
8. } 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
ostream istream
iostream
fstream
ofstream
cout
ifstreamcin
ostringstring
istringstream
stringstream
10. Ø 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