23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

are addressed. Virtual memory does not limit the programmer to the constra<strong>in</strong>t of<br />

the <strong>in</strong>ternal memory size. The concept of br<strong>in</strong>g<strong>in</strong>g data <strong>in</strong>to primary memory is<br />

called cach<strong>in</strong>g, <strong>and</strong> it is motivated by temporal locality. For, by br<strong>in</strong>g<strong>in</strong>g data <strong>in</strong>to<br />

primary memory, we are hop<strong>in</strong>g that it will be accessed aga<strong>in</strong> soon, <strong>and</strong> we will be<br />

able to respond quickly to all the requests for this data that come <strong>in</strong> the near future.<br />

The second design choice is motivated by spatial locality. Specifically, if data<br />

stored at a secondary+level memory location l is accessed, then we br<strong>in</strong>g <strong>in</strong>to<br />

primary+level memory, a large block of contiguous locations that <strong>in</strong>clude the<br />

location l. (See Figure 14.4.) This concept is known as block<strong>in</strong>g, <strong>and</strong> it is motivated<br />

by the expectation that other secondary+level memory locations close to l will soon<br />

be accessed. In the <strong>in</strong>terface between cache memory <strong>and</strong> <strong>in</strong>ternal memory, such<br />

blocks are often called cache l<strong>in</strong>es, <strong>and</strong> <strong>in</strong> the <strong>in</strong>terface between <strong>in</strong>ternal memory<br />

<strong>and</strong> external memory, such blocks are often called pages.<br />

Figure 14.4: Blocks <strong>in</strong> external memory.<br />

When implemented with cach<strong>in</strong>g <strong>and</strong> block<strong>in</strong>g, virtual memory often allows us to<br />

perceive secondary-level memory as be<strong>in</strong>g faster than it really is. There is still a<br />

problem, however. Primary+level memory is much smaller than secondarylevel<br />

memory. Moreover, because memory systems use block<strong>in</strong>g, any program of<br />

substance will likely reach a po<strong>in</strong>t where it requests data from secondary+level<br />

memory, but the primary memory is already full of blocks. In order to fulfill the<br />

request <strong>and</strong> ma<strong>in</strong>ta<strong>in</strong> our use of cach<strong>in</strong>g <strong>and</strong> block<strong>in</strong>g, we must remove some block<br />

from primary memory to make room for a new block from secondary memory <strong>in</strong><br />

this case. Decid<strong>in</strong>g how to do this eviction br<strong>in</strong>gs up a number of <strong>in</strong>terest<strong>in</strong>g data<br />

structure <strong>and</strong> algorithm design issues.<br />

Cach<strong>in</strong>g <strong>Algorithms</strong><br />

There are several web applications that must deal with revisit<strong>in</strong>g <strong>in</strong>formation<br />

presented <strong>in</strong> web pages. These revisits have been shown to exhibit localities of<br />

reference, both <strong>in</strong> time <strong>and</strong> <strong>in</strong> space. To exploit these localities of reference, it is<br />

often advantageous to store copies of web pages <strong>in</strong> a cache memory, so these pages<br />

897

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

Saved successfully!

Ooh no, something went wrong!