Java Reference
In-Depth Information
/ ** MemoryManagerinterface * /
interfaceMemManADT{
/ ** Storearecordandreturnahandletoit * /
publicMemHandleinsert(byte[]info);
/ ** Getbackacopyofastoredrecord * /
publicbyte[]get(MemHandleh);
/ ** Releasethespaceassociatedwitharecord * /
publicvoidrelease(MemHandleh);
}
Figure12.8 A simple ADT for a memory manager.
the restricted order of insertions and deletions makes this easy to deal with. But
in a language like C ++ or Java, programmers can allocate and deallocate space in
complex ways through use of new . Where does this space come from? This section
discusses memory management techniques for the general problem of handling
space requests of variable size.
The basic model for memory management is that we have a (large) block of
contiguous memory locations, which we will call the memory pool. Periodically,
memory requests are issued for some amount of space in the pool. The memory
manager has the job of finding a contiguous block of locations of at least the re-
quested size from somewhere within the memory pool. Honoring such a request
is called a memory allocation. The memory manager will typically return some
piece of information that the requester can hold on to so that later it can recover
the record that was just stored by the memory manager. This piece of information
is called a handle. At some point, space that has been requested might no longer
be needed, and this space can be returned to the memory manager so that it can be
reused. This is called a memory deallocation. The memory manager should then
be able to reuse this space to satisfy later memory requests. We can define an ADT
for the memory manager as shown in Figure 12.8.
The user of the MemManager ADT provides a pointer (in parameter info ) to
space that holds some record or message to be stored or retrieved. This is similar
to the Java basic file read/write methods presented in Section 8.4. The fundamental
idea is that the client gives messages to the memory manager for safe keeping. The
memory manager returns a “receipt” for the message in the form of a MemHandle
object. Of course to be practical, a MemHandle must be much smaller than the
typical message to be stored.
The client holds the MemHandle object until it
wishes to get the message back.
Method insert lets the client tell the memory manager the length and con-
tents of the message to be stored. This ADT assumes that the memory manager will
remember the length of the message associated with a given handle (perhaps in the
Search WWH ::




Custom Search