13.07.2015 Views

13.1 through 13.5, 13.10 and 13.11

13.1 through 13.5, 13.10 and 13.11

13.1 through 13.5, 13.10 and 13.11

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13 Disk Storage, Basic File Structures, <strong>and</strong> Hashingtypical progranmers-need to be more complex thirn those for fixed-lengthrecorcls, where the starting position <strong>and</strong> size of each field are known <strong>and</strong> fixed.613.4.3 Record Blocking <strong>and</strong> Spannedversus Unspanned RecordsThe records of a file must be allocated to disk blocks because a block is the unit ofdata transfer between disk <strong>and</strong> memory. When the block size is larger than the recordsize, each block will contain numerous records, although sorre files may have unusuallylarge records that cannot flt in one block. Suppose that the block size isB bytes. For a file of l'ixed-length records of size R bytes, with B > R, we can fitItfr =lB/R) records per block, where the l(x)) (Jloor function) rounds down rhe numberx to an integer. The value b/r is called the blocking factor for the file. In general,R may not divide B exactly, so we have sor-ne unused space in each block equal toB - (bli * R) bytesTo utilize this unused space, we can stole part of a record on one block <strong>and</strong> the reston another. A pointer at the end of the frrst block points to the block containing theremainder of the record in case it is not the next consecutive block on disk. Thisorganization is called spanned because records can span more than one block.Whenever a record is larger than a block, rve ntust use a spanned organization. Ifrecords are not allowed to cross block boundaries, the organization is calledunspanned. This is used with fixed-length records having B > R because it makeseach record start at a known location in the block, simplifying record processing. Forvariable-length records, either a spanned or an unspanned organization can be used.If the average record is large, it is advantageous to use spanning to reduce the lostspace in each block. Figure 13.6 illustrate spirnned versus Llnspilnned organization.For variable-length records using spar.rr.red organization, each block may store a differentnumber of records. In this case, the blocking factor bfr represents the averageFigure 13.6Types of record organization. (a) Unspanned. (b) Spanned.Block iRecord1 | Record2 | Record3Block i + 1Record4 | Recordb I Record6(b)Block iBlock i + 1Record4(rest) I Record5 |Record6 | RecordT I P6. Other schemes are also possible for representing variable-length records.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!