Files - File I/O Files 7.1 Chapter Seven Chapter Overview...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
File I/O Beta Draft - Do not distribute © 2001, By Randall Hyde Page 517 Files Chapter Seven 7.1 Chapter Overview In this chapter you will learn about the fi le persistent data type. In most assembly languages, fi le I/O is a major headache. Not so in HLA with the HLA Standard Library . File I/O is no more dif fi cult than writing data to the standard output de vice or reading data from the standard input de vice. In this chapter you will learn ho w to create and manipulate sequential and random-access fi les. 7.2 File Organization A fi le is a collection of data that the system maintains in persistent storage. Persistent means that the storage is non-v olatile – that is, the system maintains the data e v en after the program terminates; indeed, e v en if you shut of f system po wer . F or this reason, plus the f act that dif ferent programs can access the data in a fi le, applications typically use fi les to maintain data across e x ecutions of the application and to share data with other applications. The operating system typically sa v es fi le data on a disk dri v e or some other form of secondary storage de vice. As you may recall from the chapter on the memory hierarch y (see The Memory Hierarch y ” on page 303 ), secondary storage (disk dri v es) is much slo wer than main memory . Therefore, you generally do not store data that a program commonly accesses in fi les during program e x ecution unless that data is f ar too lar ge to fi t into main memory (e.g., a lar ge database). Under Linux and W indo ws, a standard fi le is simply a stream of bytes that the operating system does not interpret in an y w ay . It is the responsibility of the application to interpret this information, much the same as it is your application’ s responsibility to interpret data in memory . The stream of bytes in a fi le could be a sequence of ASCII characters (e.g., a te xt fi le) or the y could be pix el v alues that form a 24-bit color photo - graph. Files generally tak e one of tw o dif ferent forms: sequential fi les or r andom access fi les . Sequential fi les are great for data you read or write all at once; random access fi les w ork best for data you read and write in pieces (or re write, as the case may be). F or e xample, a typical te xt fi le (lik e an HLA source fi le) is usually a sequential fi le. Usually your te xt editor will read or write the entire fi le at once. Similarly , the HLA com - piler will read the data from the fi le in a sequential f ashion without skipping around in the fi le. A database fi le, on the other hand, requires random access since the application can read data from an ywhere in the fi le in response to a query . 7.2.1 Files as Lists of Records A good vie w of a fi le is as a list of records. That is, the fi le is brok en do wn into a sequential string of records that share a common structure. A list is simply an open-ended single dimensional array of items, so we can vie w a fi le as an array of records. As such, we can inde
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 24

Files - File I/O Files 7.1 Chapter Seven Chapter Overview...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online