MemoryStream.GetBuffer returns 1024 bytes

  • Thread starter Thread starter Brian Mitchell
  • Start date Start date
B

Brian Mitchell

Hello, I am using a MemoryStream to serialize a class but when I use the
GetBuffer method it returns exactly 1024 bytes even though the stream is
only 675 bytes.

If I look at the MemoryStream.Length it shows 675 and even if I do a ?
MemoryStream.GetBuffer in the command window it will will try to return
1024.

I figgure I am doing something wrong here especially since this is my first
time with the MemoryStream class. Can anyone give me some pointers??

Thanks!!
Brian
 
The 1024 is the size of the internal buffer being used to be written to and read from. As more is written to it, the buffer is
increased in large chunks at a time, not just one byte. You have only used 675 bytes of the allocated buffer. So GetBuffer
returns the entire buffer, not just what you have used.

Kelly
 
Thank you, I guess I have a bit more to learn about the streams. I used the
..ToArray method to get the corret byte data.

Thanks for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top