473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Reuse MemoryStream?

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

Nov 15 '05 #1
3 15000
Did you try MemoryStream.Seek to just set back to origin?

"Drew" <so*****@hotmail.com> wrote in message
news:#i**************@TK2MSFTNGP09.phx.gbl...
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


Nov 15 '05 #2
Drew <so*****@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
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.

--
Best regards

Carlos Guzmán Álvarez
Vigo-Spain

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicolas | last post by:
Hi Everybody, I'm working with the MemoryStream and I'm having problems with the ReadBytes method. When I use it, this method never returns bytes!!!! MemoryStream sw = new MemoryStream();...
2
by: SQLScott | last post by:
For some reason I am drawing a blank on this, so I would be extremely greatful if someone could help me out. I am trying to get a MemoryStream out of a Byte array. How do I get it back out? ...
3
by: Marc Thompson | last post by:
Hi there, I have the following: Dim objResponse As WebResponse = objReq.GetResponse Dim objStream As IO.Stream objStream = objResponse.GetResponseStream Then, I read some Bytes from...
13
by: Don | last post by:
When I run the following code, the MemoryStream's Position is always set to 762 instead of 0, which is what I would expect: Dim bmp As Image Dim ms As MemoryStream bmp = New...
10
by: Asaf | last post by:
Hi, I am trying to Compress & Decompress a DataSet. When running this code I am receiving the error: System.Xml.XmlException was unhandled Message="Root element is missing."...
4
by: Heron | last post by:
Hi, Could someone explain me why the following code doesn't work? The memorystream always remains with length 0. MemoryStream input = new MemoryStream();
4
by: | last post by:
Hi all, I want to create a method that does the following: 1) Programmatically instantiate a new XmlDataSource control 2) For each file in a named directory, make a "FileSystemItem" element 3)...
3
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I am using dotnet remoting with a binarry formatter. I have a property that returns a memorystream that has had a file loaded into it. When I try to access this property though I get an...
3
by: =?Utf-8?B?VmljdG9y?= | last post by:
Hi, Could you tell me can I keep the MemoryStream open and "close" the BinaryReader? As the MemoryStream is used for buffering the TCP data and BinaryReader is only used to read the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.