microsoft / Microsoft.IO.RecyclableMemoryStream

A library to provide pooling for .NET MemoryStream objects to improve application performance.
MIT License
1.99k stars 206 forks source link

How to read and send recyclable memory stream parallel to multiple destinations #358

Open vanand-conga opened 1 week ago

vanand-conga commented 1 week ago

Hi,

I'm working in a document processing app, where we need to pass large documents (20MB). I read the document as a stream and populate it to recyclable memory stream and feed it to Aspose Word library. The library after processing the document returns another stream which I also can copy to recyclable stream. Now I need to send the output document stream to multiple destinations like email, database etc. How can I deliver the stream to multiple places in parallel? Do I need to clone it? Does cloning cause more memory issues?

benmwatson commented 1 week ago

Cloning the stream would likely annul the benefits of using this library. The point of RMS is to avoid allocating new bytes, and then ideally copying those bytes everywhere.

Other specifics would really depend on the libraries and application your using in. If they can take read-only spans, buffers with length, streams, or other equivalent interfaces to memory, then theoretically there's no limit to how many places you can use these bytes--as long as the access is read-only.