From: Tony Johansson on
Hi!

Note as I have noticed you can specify a larger buffer for StreamWrite in
the c-tor for StreamWrite and therefore skip the BufferedStream.

I just wonder if I still want to use a BufferedStream or a MemoryStream
aren't these more or less the same thing.
I mean if I use a BufferedStream this buffer is located in the memory. So I
mean that the functionality will be
about the same.

So the purpose of a BufferedStream is to keep a buffer so the number of
writes to the underlaying stream will be lower and
therefore increased performance.
The purpose with MemoryStream it to write to the MemoryStream from example a
StreamWriter and then use the MemoryStream with an encapulated FileStream to
write to a file.

So as a summary I see these two MemoryStream and the BufferedStream as doing
more or less the same thing ?

Do you agree with me ?


//Tony


From: Patrice on
By this criteria you'll find numerous things that are all stored in
memory...

Use a memory stream when you want to store the whole content in memory.
Use a buffered stream when you want to use a buffer around a stream that
doesn't already use one.

Being close doesn't mean you should use only one of them. They are here at
your disposal to be used when appropriate.

--
Patrice

From: Arne Vajhøj on
On 20-03-2010 05:28, Tony Johansson wrote:
> Note as I have noticed you can specify a larger buffer for StreamWrite in
> the c-tor for StreamWrite and therefore skip the BufferedStream.
>
> I just wonder if I still want to use a BufferedStream or a MemoryStream
> aren't these more or less the same thing.
> I mean if I use a BufferedStream this buffer is located in the memory. So I
> mean that the functionality will be
> about the same.
>
> So the purpose of a BufferedStream is to keep a buffer so the number of
> writes to the underlaying stream will be lower and
> therefore increased performance.
> The purpose with MemoryStream it to write to the MemoryStream from example a
> StreamWriter and then use the MemoryStream with an encapulated FileStream to
> write to a file.
>
> So as a summary I see these two MemoryStream and the BufferedStream as doing
> more or less the same thing ?
>
> Do you agree with me ?

No.

MemoryStream is usually used for conversions bytes<->something and
the stuff is not to be written to disk or network.

BufferedStream is used when disk or network IO needs buffering
(and there is not something on top of it that provide such
capabilities). Sometimes you do not use *Reader/*Writer for IO.

Arne

From: Tony Johansson on
"Arne Vajh�j" <arne(a)vajhoej.dk> skrev i meddelandet
news:4ba4c05d$0$281$14726298(a)news.sunsite.dk...
> On 20-03-2010 05:28, Tony Johansson wrote:
>> Note as I have noticed you can specify a larger buffer for StreamWrite in
>> the c-tor for StreamWrite and therefore skip the BufferedStream.
>>
>> I just wonder if I still want to use a BufferedStream or a MemoryStream
>> aren't these more or less the same thing.
>> I mean if I use a BufferedStream this buffer is located in the memory. So
>> I
>> mean that the functionality will be
>> about the same.
>>
>> So the purpose of a BufferedStream is to keep a buffer so the number of
>> writes to the underlaying stream will be lower and
>> therefore increased performance.
>> The purpose with MemoryStream it to write to the MemoryStream from
>> example a
>> StreamWriter and then use the MemoryStream with an encapulated FileStream
>> to
>> write to a file.
>>
>> So as a summary I see these two MemoryStream and the BufferedStream as
>> doing
>> more or less the same thing ?
>>
>> Do you agree with me ?
>
> No.
>
> MemoryStream is usually used for conversions bytes<->something and
> the stuff is not to be written to disk or network.
>
> BufferedStream is used when disk or network IO needs buffering
> (and there is not something on top of it that provide such
> capabilities). Sometimes you do not use *Reader/*Writer for IO.
>
> Arne

Hi!

What do you mean with this row that you wrote.
>MemoryStream is usually used for conversions bytes<->something and
>the stuff is not to be written to disk or network

Do you mean the usage is like a common area that is used for communication ?
But I mean if you use MemoryStream as I describe it will remind a lot to the
functionallity of BufferedStream

//Tony


From: Arne Vajhøj on
On 20-03-2010 10:03, Tony Johansson wrote:
> "Arne Vajh�j"<arne(a)vajhoej.dk> skrev i meddelandet
> news:4ba4c05d$0$281$14726298(a)news.sunsite.dk...
>> On 20-03-2010 05:28, Tony Johansson wrote:
>>> Note as I have noticed you can specify a larger buffer for StreamWrite in
>>> the c-tor for StreamWrite and therefore skip the BufferedStream.
>>>
>>> I just wonder if I still want to use a BufferedStream or a MemoryStream
>>> aren't these more or less the same thing.
>>> I mean if I use a BufferedStream this buffer is located in the memory. So
>>> I
>>> mean that the functionality will be
>>> about the same.
>>>
>>> So the purpose of a BufferedStream is to keep a buffer so the number of
>>> writes to the underlaying stream will be lower and
>>> therefore increased performance.
>>> The purpose with MemoryStream it to write to the MemoryStream from
>>> example a
>>> StreamWriter and then use the MemoryStream with an encapulated FileStream
>>> to
>>> write to a file.
>>>
>>> So as a summary I see these two MemoryStream and the BufferedStream as
>>> doing
>>> more or less the same thing ?
>>>
>>> Do you agree with me ?
>>
>> No.
>>
>> MemoryStream is usually used for conversions bytes<->something and
>> the stuff is not to be written to disk or network.
>>
>> BufferedStream is used when disk or network IO needs buffering
>> (and there is not something on top of it that provide such
>> capabilities). Sometimes you do not use *Reader/*Writer for IO.
>
> What do you mean with this row that you wrote.
>> MemoryStream is usually used for conversions bytes<->something and
>> the stuff is not to be written to disk or network
>
> Do you mean the usage is like a common area that is used for communication ?
> But I mean if you use MemoryStream as I describe it will remind a lot to the
> functionallity of BufferedStream

Yes.

But that is not a typical usage of MemoryStream.

Typical you use MemoryStream when you are reading from
to writing to a byte array that is not a simple buffer.

Example:

public class Ser<T>
{
public static byte[] Object2ByteArray(T o)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, o);
return ms.ToArray();
}
public static string Object2String(T o)
{
return Convert.ToBase64String(Object2ByteArray(o));
}
public static T ByteArray2Object(byte[] b)
{
MemoryStream ms = new MemoryStream(b);
BinaryFormatter bf = new BinaryFormatter();
ms.Position = 0;
return (T)bf.Deserialize(ms);
}
public static T String2Object(string s)
{
return ByteArray2Object(Convert.FromBase64String(s));
}
}

where String2Object(foobar) can be inserted in a database VARCHAR field.

Arne