[Mono-dev] Should we replace MemoryStream?

Thad Thompson TThompson at Nucsafe.com
Tue Nov 10 10:35:25 EST 2009

Hey Ya'll,
I'm all about performance, but there's more to Robert Jordan's point
than just the access time. As it's always been described and
implemented, a MemoryStream is an abstraction over an array of bytes.
GetBuffer is an escape interface which allows me to drop and resume that
abstraction whenever it's convenient. It would be unfortunate if this
pattern were broken everywhere it is currently used:

static void Main(string[] args)
    var m = new MemoryStream();
    var b = Encoding.UTF8.GetBytes("HELO World");
    m.Write(b, 0, b.Length);

    var vBuf = m.GetBuffer();

    // Swap
    var t = vBuf[0];
    vBuf[0] = vBuf[1];
    vBuf[1] = t;

    // Prints "EHLO World"

If we're really worried about memory buffers and remoting performance,
I'd humbly suggest that perhaps the
System.ServiceModel.Channels.BufferManager class could use some lovin.


More information about the Mono-devel-list mailing list