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...

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 293Secondary S<strong>to</strong>rage(on disk)01 7234567891538Main Memory(in RAM)Figure 8.5 An illustration of virtual memory. The complete collection of informationresides in the slower, secondary s<strong>to</strong>rage (on disk). Those sec<strong>to</strong>rs recentlyaccessed are held in the fast main memory (in RAM). In this example, copies ofSec<strong>to</strong>rs 1, 7, 5, 3, <strong>and</strong> 8 from secondary s<strong>to</strong>rage are currently s<strong>to</strong>red in the mainmemory. If a memory access <strong>to</strong> Sec<strong>to</strong>r 9 is received, one of the sec<strong>to</strong>rs currentlyin main memory must be replaced.the buffer pool class itself. The first approach is <strong>to</strong> pass “messages” between thetwo. This approach is illustrated by the following abstract class:/** ADT for buffer pools using the message-passing style */public interface BufferPoolADT {/** Copy "sz" bytes from "space" <strong>to</strong> position "pos" in thebuffered s<strong>to</strong>rage */public void insert(byte[] space, int sz, int pos);}/** Copy "sz" bytes from position "pos" of the buffereds<strong>to</strong>rage <strong>to</strong> "space". */public void getbytes(byte[] space, int sz, int pos);This simple class provides an interface with two member functions, insert<strong>and</strong> getbytes. The information is passed between the buffer pool user <strong>and</strong> thebuffer pool through the space parameter. This is s<strong>to</strong>rage space, provided by thebufferpool client <strong>and</strong> at least sz bytes long, which the buffer pool can take informationfrom (the insert function) or put information in<strong>to</strong> (the getbytesfunction). Parameter pos indicates where the information will be placed in the

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

Saved successfully!

Ooh no, something went wrong!