CS215 - Lec 6 record index

360 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
360
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
24
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

CS215 - Lec 6 record index

  1. 1. }  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
  2. 2. Dr. Hussien M. Sharaf 3 Fixed length of bytes Variable length Length indicator Record delimiter Record index
  3. 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 }  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
  4. 4. }  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
  5. 5. Ø 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
  6. 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 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
  7. 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 ostream istream iostream fstream ofstream cout ifstreamcin ostringstring istringstream stringstream
  8. 8. http://www.cplusplus.com/reference/iostream/
  9. 9. Ø 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

×