I was considering using UnmanagedMemoryStream rather than MemoryStream for dealing with incoming (and perhaps outgoing?) packets in a network server. What I hope to achieve is less copying of values, and if possible, avoid copying to the heap (too much).
For example, for an incoming packet, one could do:
fixed (byte* p = &data) // where data comes from a socket receive
{
using (var stream = new UnmanagedMemoryStream(p, data.Length))
{
// do handling here...
}
}
Still, I'm not quite sure if there is any realistic benefit in doing this. Could anyone come with some feedback as to whether or not there would be any value in doing this, rather than using the good old managed MemoryStream?
Thanks in advance.