Reuse MemoryStream?

  • Thread starter Thread starter Drew
  • Start date Start date
D

Drew

I've created a new MemoryStream object that takes a byte array but
I thought it would be a good idea to reuse it instead
of creating a bunch of new ones.

How do I sorta clear it out and reuse it with a different byte array?

Should I call flush() and then write()?

Drew
 
Drew said:
I've created a new MemoryStream object that takes a byte array but
I thought it would be a good idea to reuse it instead
of creating a bunch of new ones.

How do I sorta clear it out and reuse it with a different byte array?

Should I call flush() and then write()?

No - that wouldn't reset it. Personally I'd just create a new one each
time.
 
Hello:
I've created a new MemoryStream object that takes a byte array but
I thought it would be a good idea to reuse it instead
of creating a bunch of new ones.

How do I sorta clear it out and reuse it with a different byte array?

Should I call flush() and then write()?

Try this:

MemoryStream ms = new MemoryStream();

...

ms.SetLength(0);
ms.Position = 0;



Hope this helps.
 
Back
Top