In your opinions, is it better to return a newly allocated memory stream from a function, or pass it into the function? For instance,
void Foo(MemoryStream m) { m.Write(somebuffer, 0, somebuffer.Length); }
or
void MemoryStream Foo() { MemoryStream retval = new MemoryStream(); retval.Write(somebuffer, 0, somebuffer.Length); return retval; }
This is a bit like asking whether you should return a string from a method or take a StringBuilder and append to it. The answer depends on what the use case is.
Is it likely that the caller will want to call your method with an existing stream containing some data? Might they want to call it several times using the same stream? If so, the version taking the MemoryStream would be more efficient. On the other hand, if they only want the data once, returning it as a MemoryStream (or, more simply, as a byte array) may well be more appropriate.
Unfortunately from the description we can’t really tell what’s going on. Of course, you could implement both as overloads and call one from the other.