CSharpTest.Net
SegmentedMemoryStream Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace : SegmentedMemoryStream Class

Glossary Item Box

Creates a stream over an array of byte arrays in memory to reduce use of the LOH and array resizing operation.

Syntax

Visual Basic (Declaration) 
Public Class SegmentedMemoryStream 
   Inherits System.IO.Stream
C# 
public class SegmentedMemoryStream : System.IO.Stream 

Example

Library/Library.Test/TestSegmentedStream.cs

C#Copy Code
using (SegmentedMemoryStream ms = new SegmentedMemoryStream(5))
{
    Write(ms, "12345");
    Write(ms, "abcd");
    Write(ms, "ABCDEF");
    Write(ms, "12345");
    Write(ms, "");

    ms.Flush();
    Assert.AreEqual(20L, ms.Length);
    Assert.AreEqual(20L, ms.Position);

    ms.Position = 0;
    Assert.AreEqual("12345abcdABCDEF12345", Read(ms, (int)ms.Length));

    ms.Position = 5;
    Assert.AreEqual("a", Read(ms, 1));
    Assert.AreEqual("bcd", Read(ms, 3));
    Assert.AreEqual("ABCDEF", Read(ms, 6));
    Assert.AreEqual("12345", Read(ms, 5));
    Assert.AreEqual(0, ms.Read(new byte[10], 0, 10));
}
VB.NETCopy Code
Using ms As New SegmentedMemoryStream(5)
    Write(ms, "12345")
    Write(ms, "abcd")
    Write(ms, "ABCDEF")
    Write(ms, "12345")
    Write(ms, "")

    ms.Flush()
    Assert.AreEqual(20L, ms.Length)
    Assert.AreEqual(20L, ms.Position)

    ms.Position = 0
    Assert.AreEqual("12345abcdABCDEF12345", Read(ms, DirectCast(ms.Length, Integer)))

    ms.Position = 5
    Assert.AreEqual("a", Read(ms, 1))
    Assert.AreEqual("bcd", Read(ms, 3))
    Assert.AreEqual("ABCDEF", Read(ms, 6))
    Assert.AreEqual("12345", Read(ms, 5))
    Assert.AreEqual(0, ms.Read(New Byte(10) {}, 0, 10))
End Using

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.IO.Stream
         CSharpTest.Net.IO.SegmentedMemoryStream
            CSharpTest.Net.IO.SharedMemoryStream

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys