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.

296 Chap. 8 File Processing <strong>and</strong> External Sortingtents must then issue a readBlock request <strong>to</strong> read the data from disk in<strong>to</strong> thebuffer, <strong>and</strong> then a get<strong>Data</strong>Pointer request <strong>to</strong> gain direct access <strong>to</strong> the buffer’sdata contents./** Improved ADT for buffer pools using the buffer-passingstyle. Most user functionality is in the buffer class,not the buffer pool itself. *//** A single buffer in the buffer pool */public interface BufferADT {/** Read the associated block from disk (if necessary) <strong>and</strong>return a pointer <strong>to</strong> the data */public byte[] readBlock();}/** Return a pointer <strong>to</strong> the buffer’s data array(without reading from disk) */public byte[] get<strong>Data</strong>Pointer();/** Flag the buffer’s contents as having changed, so thatflushing the block will write it back <strong>to</strong> disk */public void markDirty();/** Release the block’s access <strong>to</strong> this buffer. Furtheraccesses <strong>to</strong> this buffer are illegal. */public void releaseBuffer();/** The bufferpool */public interface BufferPoolADT {}/** Relate a block <strong>to</strong> a buffer, returning a pointer <strong>to</strong> abuffer object */Buffer acquireBuffer(int block);Clearly, the buffer-passing approach places more obligations on the user of thebuffer pool. These obligations include knowing the size of a block, not corruptingthe buffer pool’s s<strong>to</strong>rage space, <strong>and</strong> informing the buffer pool both when a blockhas been modified <strong>and</strong> when it is no longer needed. So many obligations make thisapproach prone <strong>to</strong> error. An advantage is that there is no need <strong>to</strong> do an extra copystep when getting information from the user <strong>to</strong> the buffer. If the size of the recordss<strong>to</strong>red is small, this is not an important consideration. If the size of the records islarge (especially if the record size <strong>and</strong> the buffer size are the same, as typically is thecase when implementing B-trees, see Section 10.5), then this efficiency issue mightbecome important. Note however that the in-memory copy time will always be farless than the time required <strong>to</strong> write the contents of a buffer <strong>to</strong> disk. For applications

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

Saved successfully!

Ooh no, something went wrong!