Virtual memory and streams

This chapter focuses on memory streams to show how to associate streams with storage. The basic principles hold whether the underlying storage is virtual memory or a disk file. Once a stream is instantiated to work with either virtual memory (TChunkyStream or TContiguousMemoryStream) or a disk file (TFileStream), you need not worry further about differences.

Associated with Memory streams are objects that are instantiated from a subclass of TChunkyMemory. This relationship is shown in the class hierarchy in
Figure 45.


TChunkyMemory is an abstract class defining protocol inherited by concrete classes intended to manage virtual memory. Note that TChunkyStream references an instance of TChunkyMemory through a pointer even though TChunkyMemory is an abstract class that should not be instantiated directly. Through this pointer reference, TChunkyStreams can invoke virtual methods in concrete subclasses of TChunkyMemory. The protocol for these memory objects is shown in Figure 18

.

You don't need to worry about the protocol for TChunkyMemory or its descendants, except to create instances of these descendants (such as THeapChunkyMemory) which you will pass as arguments to constructors for memory streams. Sample code that does this can be found under "Using streams." TChunkyMemory is an abstract base class that manages memory in chunks of a specified size.

Memory is allocated in chunks (specified by SetChunkSize), but the user still views the memory as a series of bytes. THeapChunkyMemory is a concrete class that manages chunky memory that has been allocated on a heap. The heap might be allocated from system resources by default, or from a client-specified heap as an alternative. The allocation of heap memory is really the only issue that clients of memory streams need to be concerned with. The rest of the protocol for dealing with subclasses of TChunkyMemory is handled automatically by the streams themselves.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker