MemoryStream eats a big system memory, to evit this, you can use this custom stream made by me instead of MemoryStream.
class CustomStream : Stream
{
string _T;
long _pos;
System.Text.Encoding _encoder = Encoding.Default;
public CustomStream()
: this("")
{
}
public byte[] GetBytes()
{
return _encoder.GetBytes(_T);
}
public CustomStream(string BaseText)
{
_T = BaseText;
_pos = 0;
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override void Flush()
{
_T = "";
_pos = 0;
}
public override long Length
{
get { return _T.Length; }
}
public override long Position
{
get
{
return _pos;
}
set
{
_pos = value;
}
}
public override int Read(byte[] buffer, int offset, int count)
{
int ret = 0;
for (int i = 0; i < count; i++)
{
if (_T.Length <= _pos)
{
break;
}
buffer[i] = (byte)_T[(int)_pos];
_pos++;
ret++;
}
return ret;
}
public override long Seek(long offset, SeekOrigin origin)
{
if (origin != SeekOrigin.Begin)
{
throw new NotImplementedException();
}
_pos = offset;
return _pos;
}
public override void SetLength(long value)
{
if (_T.Length > value)
{
string nstr = "";
for (int i = 0; i < value; i++)
{
nstr += _T[i];
}
_T = nstr;
}
else if (_T.Length < value)
{
for (int i = 0; i < value - _T.Length; i++)
{
_T += "\0";
}
}
}
public override void Write(byte[] buffer, int offset, int count)
{
_T += _encoder.GetString(buffer, offset, count);
}
}
Some fixes in edit since: 30/10 12:43 (GMT-3)