M
Markus Ewald
I guess this counts as a rather adventurous use case, but can the
MemoryStream class somehow be used for buffers (eg. in socket
communications) that fill the MemoryStream's internal byte array
directly instead of using the stream's Write() method?
I could of course just use a plain byte array, bit this would be more
convenient to manage and I wouldn't need to copy around received data
before it could be parsed using a BinaryReader.
The following code snippet doesn't seem to work:
System.IO.MemoryStream ms = new System.IO.MemoryStream(100);
// Bypass the Write() method
// (assume this was a Socket.Receive() call)
ms.GetBuffer()[0] = 1;
ms.GetBuffer()[1] = 2;
ms.GetBuffer()[2] = 3;
ms.GetBuffer()[3] = 4;
ms.SetLength(4);
// ms now has a Length of 4 but its contents have been cleared
All I need would be a way to tell the MemoryStream that its actual size
is not what it thinks it is
-Markus-
MemoryStream class somehow be used for buffers (eg. in socket
communications) that fill the MemoryStream's internal byte array
directly instead of using the stream's Write() method?
I could of course just use a plain byte array, bit this would be more
convenient to manage and I wouldn't need to copy around received data
before it could be parsed using a BinaryReader.
The following code snippet doesn't seem to work:
System.IO.MemoryStream ms = new System.IO.MemoryStream(100);
// Bypass the Write() method
// (assume this was a Socket.Receive() call)
ms.GetBuffer()[0] = 1;
ms.GetBuffer()[1] = 2;
ms.GetBuffer()[2] = 3;
ms.GetBuffer()[3] = 4;
ms.SetLength(4);
// ms now has a Length of 4 but its contents have been cleared
All I need would be a way to tell the MemoryStream that its actual size
is not what it thinks it is
-Markus-