Share via


MemoryStream Class

Creates a stream whose backing store is memory.

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

Syntax

public class MemoryStream

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 view of the data, and can only be written to. 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.

Version Information

Available in the .NET Micro Framework versions 3.0, 4.0, 4.1, and 4.2.

See Also

Reference

MemoryStream Members
System.IO Namespace