Ignore this subliminal message. Ignore this subliminal message. Ignore this subliminal message. DRINK COKE. Ignore this subliminal message. Ignore this subliminal message. DRINK COKE. Ignore this subliminal message. Ignore this subliminal message. DRINK COKE. Ignore this subliminal message. Ignore this subliminal message.
File Handling
File Access Methods:
Sequential ->     The file is read from the beginning. It isn’t possible to move to a certain record within the file. The main advantage for sequential files is that they are relatively small. The disadvantage is that in order to reach a certain record, the contents of the file up until that point have to be read, slowing the access down.
Direct ->     The file can be read in any order so long as the size and nature of the records being stored in the file are known. It is possible to move to a certain record within the file. The main advantage of Direct File Access is that the speed of access is greatly increased compared to a sequential file. The main disadvantage is that the file will take up more room than a sequential file.

Serial File Organization:     A serial file stores un-ordered records (generally chronological though) in a file that requires sequential access to both read and write to.
  
 
Sequential File Organization:     A sequential file stores ordered records in a file that requires sequential access to both read and write to.
  
 
Partially-indexed Sequential File Organization:     A mixed file with sequential access to (and through) the index, then direct access to the first node in the file, and sequential access from there. than a sequential file.
  
 
Fully-Indexed File Organization:     A Fully-Indexed File has un-ordered records, a separate, and complete index which enables direct access to any node in the file. The index is read in sequentially, and from the data stored there, the read/write pointer may be moved to any node in the file.
  
 
Direct Access File Organization:     A direct access file can have either un-ordered, or ordered records. The records in a Direct Access file are read by moving the read pointer to the start of a node, then reading in the entire node at once.

e.g. of writing to a Direct Access File :


out_file.write((char *)&write_struct, sizeof(nodesize));
e.g. of reading from a Direct Access File:
out_file.read((char *)&read_struct, sizeof(nodesize));
e.g. of pointer movement out_file.seekp(sizeof(read_struct)*7); //moves the pointer to the 7th node
The exact location in the file is determined by an algorithm such as this :

(size of node)(desired node number)+(slack at beginning of file [index])

 


e.g.
//function commands
//Reads in the index, pointer is left at the end of the index
unsigned indexend = myfile.tellg(); //Sets the variable indexend to the position of the end of the index
/*read or write*/(sizeof(read_struct)*53+indexend);
//more function commands
  
 
Direct Access File Techiques applied toa  modular language (PURE):     Using PURE to move the read/write pointers to a specific record is accomplished like this: 

Assume the following:
There is already a file open, with the variable MYFILE attached to it. 
You want to access the 7th record in the file. 
The size of the nodes in the file are stored in the variable NODESIZE

Moveto(MYFILE, 7(NODESIZE))

See PURE commands at end of page
  
 
Logical vs. Physical stored Data:     Even though programs can read data in the order that it was stored, the location on the disk might not exist in the order the file was saved. The actual data might be stored interspersed with the data already existing on the drive. The hard-drive is most likely fragmented somewhat, and has holes in the data (picture). When the new file is saved, it will likely be placed into those holes, often utilizing more than one.
  
 
Need for External Sort:     Some files stored in the secondary memory (Hard-disk) are too large to be manipulated when they reside in the main memory (RAM). For this reason, many programs are resigned to work with the file on the disk. This is especially significant when external sorts (sorting routines that involve the use of files, and not memory resident data) are involved.
  
  
External Hashing:     The major difference between internal and external hashing is that, in the external environment, you must insert or delete both a data record and the corresponding index record. To insert a new data record whose search key is Searchkey, you take the following steps:
1.   Insert the data record into the data file. This record can go anywhere. To be the most efficient, insertion usually takes place where an older record has been deleted (leaving a free slot in the file). If no slots are free, the record is inserted at the end of the file.
2.   Insert a corresponding index record in the index [file or section of the file]. The index needs to be updated with the value Searchkey and a pointer value (the pointer points to where the new record was inserted). The index is usually a hash table, and most likely contains 2 arrays, one for the address of the block, the other for the key.
To delete a record whose key is Searchkey, you take the following steps:
1.   Search the index file for the corresponding index record. You apply the hash function so Searchkey. You then search the chain of index blocks pointed to by the index’s key. You then store that location into memory, and delete the index record.
2.   Delete the corresponding record. Delete the record that the index pointed to.
  
  
PURE file handling 'commands':    
open(FILEVAR) – opens a file referenced to by FILEVAR
close(FILEVAR) – closes a file referenced to by FILEVAR
filesize(FILEVAR) result integer – returns an integer indicating the file length
moveto(FILEVAR, RECORDNUMBER) - moves to a node indicateded by RECORDNUMBER in a file referenced to by FILEVAR
moveback(FILEVAR) – moves the node pointer in the file referenced to by FILEVAR back one node
endfile(FILEVAR) – closes and ends the file at the current point, discarding the contents after current node.
Take a quiz