L03
L03
L03
Contents
1 A Journey of a Byte
2 Buffer Management
3 Field Structures
4 Record Structures
7 LOGO
7
A Journey of a Byte
8 LOGO
8
1
1/8/23
A Journey of a Byte
v Suppose in our program we wrote char ch=‘p’;
file << ch;
v This causes a call to the file manager (a part of O.S.
responsible for I/O operations)
A Journey of a Byte
Step 1
Step 2
Step 3
10 LOGO
10
2
1/8/23
A Journey of a Byte
Step 4
The file manager searches a file allocation table for the physical
location of the sector that is to contain the byte.
Step 5
The file manager makes sure that the last sector in the file has
been stored in a system I/O buffer in RAM, then deposits the ‘p’
into its proper position in the buffer.
Step 6
11 LOGO
11
A Journey of a Byte
Step 7
Step 8
Step 9
12 LOGO
12
3
1/8/23
A Journey of a Byte
v Application program
§ Requests the I/O operation
13 LOGO
13
A Journey of a Byte
v I/O Processor
§ A separate chip; runs independently of CPU
§ Finds a time when drive is available to receive data and put data
in proper format for the disk
§ Sends data to disk controller
v Disk controller
§ A separate chip; instructs the drive to move R/W head
§ Sends the byte to the surface when the proper sector comes
under R/W head.
14 LOGO
14
4
1/8/23
A Journey of a Byte
v I/O Processor
§ A separate chip; runs independently of CPU
§ Finds a time when drive is available to receive data and put data
in proper format for the disk
§ Sends data to disk controller
v Disk controller
§ A separate chip; instructs the drive to move R/W head
§ Sends the byte to the surface when the proper sector comes
under R/W head.
15 LOGO
15
Buffer Management
16 LOGO
16
5
1/8/23
Buffer Management
v Buffering means working with large chunks of data in
main memory so the number of accesses to secondary
storage is reduced.
17 LOGO
17
18 LOGO
18
6
1/8/23
Buffer Bottlenecks
v Consider the following program segment:
while (1)
{
infile >> ch;
if (infile.fail())
break;
outfile << ch;
}
19 LOGO
19
Buffer Strategies
v Double Buffering: Two buffers can be used to allow
processing and I/O to overlap.
20 LOGO
20
7
1/8/23
Buffer Strategies
Double Buffering:
21 LOGO
21
Buffer Strategies
v Multiple Buffering: instead of two buffers any number of
buffers can be used to allow processing and I/O to
overlap.
v Buffer pooling:
§ There is a pool of buffers.
§ When a request for a sector is received, O.S. first looks to see that
sector is in some buffer.
§ If not there, it brings the sector to some free buffer. If no free buffer
exists, it must choose an occupied buffer. Usually, LRU (Least
Recently Used) strategy is used.
22 LOGO
22
8
1/8/23
Buffer Strategies
v Move mode (using both system buffer & program buffer)
§ moving data from one place in RAM to another before they can be
accessed
§ sometimes, unnecessary data moves
23 LOGO
23
Buffer Strategies
24 LOGO
24
9
1/8/23
25
25
Student Example
Class Structure
LOGO
26
10
1/8/23
File Types
v A file can be treated as:
1. a stream of bytes
LOGO
27
Memory File
object record
member field
LOGO
28
11
1/8/23
LOGO
29
Field Structures
30 LOGO
30
12
1/8/23
Field structures
v Methods for organizing fields are:
LOGO
31
8 10 10 15 15 15
v Advantages:
§ Easy to Read/Store
v Disadvantages:
§ Waste space with padding
LOGO
32
13
1/8/23
v Advantages:
§ Easy to jump ahead to the end of the field
v Disadvantages:
§ Long fields require more than 1 byte to store length (Max is 255)
LOGO
33
v Advantages:
§ May waste less space than with length-based
v Disadvantages:
§ Have to check every byte of field against the delimiter
LOGO
34
14
1/8/23
v Advantages:
§ Fields are self describing allows for missing fields
v Disadvantages:
§ Waste space with keywords (50% or more of the file’s space could
be taken up by the keywords )
LOGO
35
Record Structures
36 LOGO
36
15
1/8/23
Records Structures
v Methods for organizing records are:
8 10 10 15 15 15
73 Bytes
LOGO
38
16
1/8/23
LOGO
39
LOGO
40
17
1/8/23
Index File
00 47 103 153 … …
LOGO
41
LOGO
42
18