.NET Framework Class Library for Silverlight
MemoryStream Class

Creates a stream whose backing store is memory.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic (Declaration)
<ComVisibleAttribute(True)> _
Public Class MemoryStream _
    Inherits Stream
Visual Basic (Usage)
Dim instance As MemoryStream
C#
[ComVisibleAttribute(true)]
public class MemoryStream : Stream
Remarks

The MemoryStream class creates streams that have memory as a backing store instead of a disk or a network connection. MemoryStream encapsulates data stored as an unsigned byte array that is initialized upon creation of a MemoryStream object, or the array can be created as empty. The encapsulated data is directly accessible in memory. Memory streams can reduce the need for temporary buffers and files in an application.

The current position of a stream is the position at which the next read or write operation could take place. The current position can be retrieved or set through the Seek method. When a new instance of MemoryStream is created, the current position is set to zero.

Memory streams created with an unsigned byte array provide a non-resizable stream of the data. When using a byte array, you can neither append to nor shrink the stream, although you might be able to modify the existing contents depending on the parameters passed into the constructor. Empty memory streams are resizable, and can be written to and read from.

If a MemoryStream object is added to a ResX file or a .resources file, call the GetStream method at runtime to retrieve it.

If a MemoryStream object is serialized to a resource file it will actually be serialized as an UnmanagedMemoryStream. This behavior provides better performance, as well as the ability to get a pointer to the data directly, without having to go through Stream methods.

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: In Windows CE, a memory stream pasted from the Clipboard can have a slightly larger size than the memory stream copied to the Clipboard, because extra bytes can be appended to the end of the original memory stream. To accurately retrieve the memory stream either prefix the object with its size to determine how to receive it.

Inheritance Hierarchy

System..::.Object
  System.IO..::.Stream
    System.IO..::.MemoryStream
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Tags :


Page view tracker