You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also provide an existing buffer. It’s important to note that the data from this buffer will be copied into a buffer owned by the pool:
var stream = manager.GetStream("Program.Main", sourceBuffer,
0, sourceBuffer.Length);
But if using MemoryStream, no copy will be done?
var stream = new MemoryStream(sourceBuffer);
So who want to copy (and double the amount if memory used) vs. just wrap it, like MemoryStream does?
I made this mistake myself, before I read the docs I just changed all use of MemoryStream to RecyclableMemoryStream, but then I read that GetStream(byte[]) copies and changed all cases where MemoryStream was used for reading, back to MemoryStream.
I think this feature is weird (GetStream copy existing data) and could make more harm (people using as drop in replacement without reading\understanding the docs and GetStream(byte[]) increase memory use) than good? Or maybe it has a good use case, maybe an example would be nice.
Thanks.
The text was updated successfully, but these errors were encountered:
I would never recommend using this library without reading the documentation. There are lots of gotchas every time you take memory management on yourself, and this is a good example.
For cases where you just want to wrap an existing buffer in a stream, the existing MemoryStream is good.
docs says:
You can also provide an existing buffer. It’s important to note that the data from this buffer will be copied into a buffer owned by the pool:
But if using MemoryStream, no copy will be done?
So who want to copy (and double the amount if memory used) vs. just wrap it, like MemoryStream does?
I made this mistake myself, before I read the docs I just changed all use of MemoryStream to RecyclableMemoryStream, but then I read that GetStream(byte[]) copies and changed all cases where MemoryStream was used for reading, back to MemoryStream.
I think this feature is weird (GetStream copy existing data) and could make more harm (people using as drop in replacement without reading\understanding the docs and GetStream(byte[]) increase memory use) than good? Or maybe it has a good use case, maybe an example would be nice.
Thanks.
The text was updated successfully, but these errors were encountered: