12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

292 Chap. 8 File Processing <strong>and</strong> External Sortingreading blocks s<strong>to</strong>red on slower, secondary memory (such as on the disk drive).The disk s<strong>to</strong>res the complete contents of the virtual memory. Blocks are read in<strong>to</strong>main memory as dem<strong>and</strong>ed by memory accesses. Naturally, programs using virtualmemory techniques are slower than programs whose data are s<strong>to</strong>red completely inmain memory. The advantage is reduced programmer effort because a good virtualmemory system provides the appearance of larger main memory without modifyingthe program.Example 8.2 Consider a virtual memory whose size is ten sec<strong>to</strong>rs, <strong>and</strong>which has a buffer pool of five buffers associated with it. We will use a LRUreplacement scheme. The following series of memory requests occurs.9017668135171After the first five requests, the buffer pool will s<strong>to</strong>re the sec<strong>to</strong>rs in the order6, 7, 1, 0, 9. Because Sec<strong>to</strong>r 6 is already at the front, the next request can beanswered without reading new data from disk or reordering the buffers. Therequest <strong>to</strong> Sec<strong>to</strong>r 8 requires emptying the contents of the least recently usedbuffer, which contains Sec<strong>to</strong>r 9. The request <strong>to</strong> Sec<strong>to</strong>r 1 brings the bufferholding Sec<strong>to</strong>r 1’s contents back <strong>to</strong> the front. Processing the remainingrequests results in the buffer pool as shown in Figure 8.5.Example 8.3 Figure 8.5 illustrates a buffer pool of five blocks mediatinga virtual memory of ten blocks. At any given moment, up <strong>to</strong> five sec<strong>to</strong>rs ofinformation can be in main memory. Assume that Sec<strong>to</strong>rs 1, 7, 5, 3, <strong>and</strong> 8are currently in the buffer pool, s<strong>to</strong>red in this order, <strong>and</strong> that we use theLRU buffer replacement strategy. If a request for Sec<strong>to</strong>r 9 is then received,then one sec<strong>to</strong>r currently in the buffer pool must be replaced. Because thebuffer containing Sec<strong>to</strong>r 8 is the least recently used buffer, its contents willbe copied back <strong>to</strong> disk at Sec<strong>to</strong>r 8. The contents of Sec<strong>to</strong>r 9 are then copiedin<strong>to</strong> this buffer, <strong>and</strong> it is moved <strong>to</strong> the front of the buffer pool (leaving thebuffer containing Sec<strong>to</strong>r 3 as the new least-recently used buffer). If the nextmemory request were <strong>to</strong> Sec<strong>to</strong>r 5, no data would need <strong>to</strong> be read from disk.Instead, the buffer containing Sec<strong>to</strong>r 5 would be moved <strong>to</strong> the front of thebuffer pool.When implementing buffer pools, there are two basic approaches that can betaken regarding the transfer of information between the user of the buffer pool <strong>and</strong>

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

Saved successfully!

Ooh no, something went wrong!