### Instantiating a Data Stream

The constructors for the IDataStream class are private and intended only for internal use. You have two alternatives:

- If you want to read from or write to a file, you can instantiate an IDataStream if you have an IFile object. See the File System Framework documentation about Accessing the Contents of Files.
- If you want to stream data into or out of memory, you can instantiate a memory stream, using the static IDataStream::createMemoryStream function.

You will typically use a memory stream in a test program to verify the operation of the streaming functions of other classes. You create the stream, write to it, reset it and then read from it. The backing memory grows as necessary to hold the data. When you instantiate a memory stream, you can supply an optional stream format encoding. The default is IDataStream::kInteroperableBinary.

- IDataStream::kRawBinary -- This is a host-specific binary format. It has the best performance, no cross-platform interoperability, and no support for RRDC.
- IDataStream:kInteroperableBinary -- This is the canonical binary format. It supports platform-to-platform and release-to-release data compatibility.
- IDataStream::kDebug -- In this mode, the stream contents are printable ASCII and annotated with comments to aid in their interpretation.

To instantiate a memory stream with the default encoding, kInteroperableBinary, use the following code:

    IDataStream* memoryStream = IDataStream::createMemoryStream();

To use specify a stream format encoding, pass the appropriate enumerated value to the createMemoryStream function:

    IDataStream* memoryStream = IDataStream::createMemoryStream(IDataStream::kRawBinary);
    IDataStream* memoryStream = IDataStream::createMemoryStream(IDataStream::kInteroperableBinary);
    IDataStream* memoryStream = IDataStream::createMemoryStream(IDataStream::kDebug);

Introduction to the Streaming Classes
Exceptions Defined by the Streaming Classes
Data Streams
Release-to-Release Data Compatibility (RRDC)

Adding Streaming Support to Structs and Simple Classes
Creating a Streamable Class
Creating a Streamable Template Class
Instantiating a Stream Module
Enabling Release-to-Release Data Compatibility
Streaming Base Classes
Streaming Aliases and Aliased Objects
Streaming Objects Monomorphically
Streaming Objects Polymorphically
Transitioning from Older Streaming Constructs