Java Reference
In-Depth Information
become important. Note however that the in-memory copy time will always be far
less than the time required to write the contents of a buffer to disk. For applications
where disk I/O is the bottleneck for the program, even the time to copy lots of
information between the buffer pool user and the buffer might be inconsequential.
Another advantage to buffer passing is the reduction in unnecessary read operations
for data that will be overwritten anyway.
You should note that the implementations for class BufferPool above does
not use generics. Instead, the space parameter and the buffer pointer are declared
to be byte[] . When a class uses a generic, that means that the record type
is arbitrary, but that the class knows what the record type is. In contrast, using
byte[] for the space means that not only is the record type arbitrary, but also
the buffer pool does not even know what the user's record type is. In fact, a given
buffer pool might have many users who store many types of records.
In a buffer pool, the user decides where a given record will be stored but has
no control over the precise mechanism by which data are transferred to the backing
storage. This is in contrast to the memory manager described in Section 12.3 in
which the user passes a record to the manager and has no control at all over where
the record is stored.
8.4
The Programmer's View of Files
The Java programmer's logical view of a random access file is a single stream
of bytes. Interaction with a file can be viewed as a communications channel for
issuing one of three instructions: read bytes from the current position in the file,
write bytes to the current position in the file, and move the current position within
the file. You do not normally see how the bytes are stored in sectors, clusters, and
so forth. The mapping from logical to physical addresses is done by the file system,
and sector-level buffering is done automatically by the disk controller.
When processing records in a disk file, the order of access can have a great
effect on I/O time. A random access procedure processes records in an order
independent of their logical order within the file. Sequential access processes
records in order of their logical appearance within the file. Sequential processing
requires less seek time if the physical layout of the disk file matches its logical
layout, as would be expected if the file were created on a disk with a high percentage
of free space.
Java provides several mechanisms for manipulating disk files. One of the most
commonly used is the RandomAccessFile class. The following methods can
be used to manipulate information in the file.
RandomAccessFile(Stringname,Stringmode) :
Class con-
structor, opens a disk file for processing.
Search WWH ::




Custom Search