Java Reference
In-Depth Information
is easier than managing arbitrarily sized files. The cluster scheme also allows us
to relax the restriction that the memory request be serviced by a contiguous block
of memory. Most disk file managers and operating system main memory managers
work on a cluster or page system. Block management is usually done with a buffer
pool to allocate available blocks in main memory efficiently.
12.3.2
Failure Policies and Garbage Collection
At some point when processing a series of requests, a memory manager could en-
counter a request for memory that it cannot satisfy. In some situations, there might
be nothing that can be done: There simply might not be enough free memory to
service the request, and the application may require that the request be serviced im-
mediately. In this case, the memory manager has no option but to return an error,
which could in turn lead to a failure of the application program. However, in many
cases there are alternatives to simply returning an error. The possible options are
referred to collectively as failure policies.
In some cases, there might be sufficient free memory to satisfy the request,
but it is scattered among small blocks. This can happen when using a sequential-
fit memory allocation method, where external fragmentation has led to a series of
small blocks that collectively could service the request. In this case, it might be
possible to compact memory by moving the reserved blocks around so that the
free space is collected into a single block. A problem with this approach is that
the application must somehow be able to deal with the fact that its data have now
been moved to different locations. If the application program relies on the absolute
positions of the data in any way, this would be disastrous. One approach for dealing
with this problem involves the handles returned by the memory manager. A handle
works as a second level of indirection to a memory location. The memory allocation
routine does not return a pointer to the block of storage, but rather a pointer to a the
handle that in turn gives access to the storage. The handle never moves its position,
but the position of the block might be moved and the value of the handle updated.
Of course, this requires that the memory manager keep track of the handles and
how they associate with the stored messages. Figure 12.15 illustrates the concept.
Another failure policy that might work in some applications is to defer the
memory request until sufficient memory becomes available. For example, a multi-
tasking operating system could adopt the strategy of not allowing a process to run
until there is sufficient memory available. While such a delay might be annoying
to the user, it is better than halting the entire system. The assumption here is that
other processes will eventually terminate, freeing memory.
Another option might be to allocate more memory to the memory manager. In
a zoned memory allocation system where the memory manager is part of a larger
system, this might be a viable option. In a Java program that implements its own
Search WWH ::




Custom Search