11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 8.3 Buffers <strong>and</strong> Buffer Pools 281block. In particular, the following revised buffer-passing ADT does not actuallyread d<strong>at</strong>a in the acquireBuffer method. Users who wish to see the old contentsmust then issue a readBlock request to read the d<strong>at</strong>a from disk into thebuffer, <strong>and</strong> then a get<strong>D<strong>at</strong>a</strong>Pointer request to gain direct access to the buffer’sd<strong>at</strong>a 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 associ<strong>at</strong>ed block from disk (if necessary)<strong>and</strong> return a pointer to the d<strong>at</strong>a */public byte[] readBlock();}/** Return a pointer to the buffer’s d<strong>at</strong>a array(without reading from disk) */public byte[] get<strong>D<strong>at</strong>a</strong>Pointer();/** Flag buffer’s contents as having changed, so th<strong>at</strong>flushing the block will write it back to disk */public void markDirty();/** Release the block’s access to this buffer. Furtheraccesses to this buffer are illegal. */public void releaseBuffer();/** The bufferpool */public interface BufferPoolADT {}/** Rel<strong>at</strong>e a block to a buffer, returning a pointer toa buffer object */Buffer acquireBuffer(int block);Again, a mode parameter could be added to the acquireBuffer method,elimin<strong>at</strong>ing the need for the readBlock <strong>and</strong> markDirty methods.Clearly, the buffer-passing approach places more oblig<strong>at</strong>ions on the user of thebuffer pool. These oblig<strong>at</strong>ions include knowing the size of a block, not corruptingthe buffer pool’s storage 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 oblig<strong>at</strong>ions make thisapproach prone to error. An advantage is th<strong>at</strong> there is no need to do an extra copystep when getting inform<strong>at</strong>ion from the user to the buffer. If the size of the recordsstored is small, this is not an important consider<strong>at</strong>ion. 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 might

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

Saved successfully!

Ooh no, something went wrong!