Java Reference
In-Depth Information
Example8.4 Assume each sector of the disk file (and thus each block in
the buffer pool) stores 1024 bytes. Assume that the buffer pool is in the
state shown in Figure 8.5. If the next request is to copy 40 bytes begin-
ning at position 6000 of the file, these bytes should be placed into Sector 5
(whose bytes go from position 5120 to position 6143). Because Sector 5
is currently in the buffer pool, we simply copy the 40 bytes contained in
space to byte positions 880-919. The buffer containing Sector 5 is then
moved to the buffer pool ahead of the buffer containing Sector 1.
An alternative interface is to have the buffer pool provide to the user a direct
pointer to a buffer that contains the requested information. Such an interface might
look as follows:
/ ** ADTforbufferpoolsusingthebuffer-passingstyle * /
publicinterfaceBufferPoolADT{
/ ** Returnpointertotherequestedblock * /
publicbyte[]getblock(intblock);
/ ** Setthedirtybitforthebufferholding"block" * /
publicvoiddirtyblock(intblock);
//Tellthesizeofabuffer
publicintblocksize();
};
In this approach, the buffer pool user is made aware that the storage space is
divided into blocks of a given size, where each block is the size of a buffer. The user
requests specific blocks from the buffer pool, with a pointer to the buffer holding
the requested block being returned to the user. The user might then read from or
write to this space. If the user writes to the space, the buffer pool must be informed
of this fact. The reason is that, when a given block is to be removed from the buffer
pool, the contents of that block must be written to the backing storage if it has been
modified. If the block has not been modified, then it is unnecessary to write it out.
Example8.5 We wish to write 40 bytes beginning at logical position
6000 in the file. Assume that the buffer pool is in the state shown in Fig-
ure 8.5. Using the second ADT, the client would need to know that blocks
(buffers) are of size 1024, and therefore would request access to Sector 5.
A pointer to the buffer containing Sector 5 would be returned by the call to
getblock . The client would then copy 40 bytes to positions 880-919 of
the buffer, and call dirtyblock to warn the buffer pool that the contents
of this block have been modified.
 
Search WWH ::




Custom Search