File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

23
essing - Introduction MVNC 1 File Processing BASIC CONCEPTS & TERMINOLOGY

Transcript of File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

Page 1: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 1

File Processing

BASIC CONCEPTS & TERMINOLOGY

Page 2: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 2

Page 3: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 3

File Processing

What is it? Why Learn It?

Page 4: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 7

Basic Terms

File, Record, Field File

» Collection of (homogenous) records Record

» element of a file (tuple)» contains information about a single entity» Consists of fields of information about entity

Page 5: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 8

Basic Terms

Field» attribute of an entity» May be of many "types"

– string - “254 Niagra Street”– numeric value - 345– logical value - True or False– structure (e.g. date) - 12/5/96

Page 6: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 9

Files, Records, and Fields

ID First Last Phone Box

3456 Bill Gray 7634 2-5423

7264 Jenny Hill 7345 4-5432

2376 Sandy Clay 7223 2-6546

Record

FieldFile

Page 7: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 10

Example files:

consider records for:» real estate listings» student files» Books in library

Page 8: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 11

Records

Record type » record definition

or template

Record instance » a particular

record with specific data.

ID FIRST LAST BOX

3241 Alice Smith 23-546

3755 William Butler 62-819

Page 9: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 12

File access and file organization

file access - technique used to store and retrieve particular records in a file.

file organization - characteristics of how a file is structured or actually stored on the disk.

Page 10: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 13

File access and file organization

Example:» Library (books are like records)

– what is the file access?– what is the file organization?

» file cabinet– what is the file access?– what is the file organization?

Page 11: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 14

File organizations

Two major underlying file organizations Direct files

» works like an array of records in memory » user selects records directly by its position in the

file. Sequential files

» must be accessed in the order the records appear in the file.

» "tape" metaphore.

Page 12: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 15

File access techniques

Two major underlying file access techniques Direct access

» can be used with direct files to randomly select records.

» cannot be used with sequential file organization. Sequential access

» can be used with either direct or sequential organizations.

Page 13: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 16

File organization & access techniques

These techniques are basic, since directly supported by hardware.

All other (more complex) techniques built using direct & sequential.» Tree» Hashed» Indexed

Page 14: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 17

Primary vs. Secondary storage

Primary » Semiconductor memory» fast, but small, temporary, expensive» memory, registers

Secondary » Disks, Tapes» slow, but large, permanent, inexpensive» orders of magnitude slower then memory

Page 15: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 18

Motivation for File Structures

Primary Memory (RAM)» Small - 106 bytes to 108 bytes (1 - 100 megabytes)» Fast - 120* 10-9 seconds (120 nanoseconds)

access time Secondary Memory

» Large - 109 bytes to 1010 bytes (1 - 10 gigabytes)» Slow - 3*10-3 seconds (30 millisecond) access time

Page 16: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 19

Motivation for File Structures

Consider a comparison with a bookself verses a library:» Bookshelf holds 100 books» Access time is 20 seconds

How many books does library hold? How long does it take to get to library?

Page 17: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 20

Primary vs. Secondary storage

Tradeoffs - where should files and programs be kept?» primary - limited in size, loss occurs if power fails» secondary - much slower but nonvolatile

Page 18: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 21

Primary vs. Secondary storage

Balance » Consider the top of your desk vs. a file cabinet» keep what is likely to be needed soon in primary

memory » keep in secondary memory information which

hasn't been accessed recently, and isn't like to be needed soon.

» Principles of temporal and spatial locality.

Page 19: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 22

Virtual Memory

some operating systems have built-in support to balance between primary and secondary storage.» They allow programs to be much larger then memory,

and automatically "shuttle" information as needed between primary and secondary storage.

» Keep recently accessed areas of code and data in primary memory

» off-load segments not used for a while to secondary storage (or never load in the first place!)

» Thus memory appears to be bigger then it actually is

Page 20: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 23

C++ Objects and File Processing

One of our goals is to use C++ objects to represent our file components.

Consider the following C++ class:class Person{ public:

// data memberschar LastName[20], FirstName[20], Address[16]char City[16], State[3], ZipCode[10];

// methods Person (); //Default constructor Person (const char *); // Construct from string Person (const Person&); // Copy constructor};

Page 21: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 24

C++ Objects and File Processing

“public” members are accessible by users of the object

“private” members are accessible from within the object only.

Person p; // Automatic creation Person * p1_ptr = new person; // dynamic creationPerson * p2_ptr = new person(“Smith”);

cout << p.Lastname << “,“ << p.FirstName << endl;p_ptr->FirstName = p.FirstName;Person p2(p);

Page 22: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 25

C++ Objects and File Processing

Member functions

Person::Person (){ // set each field to an empty string

LastName[0]= 0; FirstName[0]= 0; Address[0]= 0; City[0]= 0; State[0]= 0; ZipCode[0]= 0;

}Person::Person (const char *LN){ // Make a Person with the Last name set

strcpy(LastName,LN); FirstName[0]=0; Address[0]=0; City[0]=0; State[0]=0; ZipCode[0]=0;

}

Page 23: File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.

File Processing - Introduction MVNC 26

C++ Objects and File Processing

Member functions

Person::Person (const Person& p); // copy constuctor{ // Make a Person with the Last name set

strcpy(LastName,p.LastName); strcpy(FirstName ,p.FirstName; strcpy(Address,p.Address; strcpy(City,p.City; strcpy(State,p.State; strcpy(ZipCode,p.ZipCode;

}