C
C#2mo ago
cheeze2000

✅ MemoryStream question

If I have a byte[], and I'm instantiating a MemoryStream with this byte array, does it occupy twice the memory? Or is the MemoryStream simply referring to the byte array instead of copying the contents in the array?
3 Replies
blueberriesiftheywerecats
Source code shows that it refers, doesn't copy
ero
ero2mo ago
but it will expand the buffer when writing to the stream past the initial capacity at which point it will allocate a new array and will no longer refer to the original that's given writable is set to true, of course. which it is by default, when you use the MemoryStream(byte[]) constructor
cheeze2000
cheeze2000OP2mo ago
thanks
Want results from more Discord servers?
Add your server