473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

i wonder why..

why would one want to use a MemoryStream?
it basically creates a stream in memory to read/write data from/to memory -
which we can accomplish with our regular objects as well. We could read
strings/bytes etc from files using the FileStream (or from network using
NetworkStream) into the relevant .NET object and work on it as long as we
wish. if needed to have the data in memory for future use, we can just leave
the object hanging around as long as we want to make use of the data .
the only thing different i would think is that while objects within the
application basically stick to the address space that the OS assigns to the
process for the application, the memorysteam is free to read/write from/to
memory thats outside the application scope. is this correct? if so, are
there any performance implications if we leave a large amount of data
hanging around in the application-specific memory as opposed to writing it
somewhere else in memory and reading it back when needed (consider reading a
large text file into a stringbuilder and leaving it hanging around for the
entire application lifetime as opposed to writing it to memory using a
MemoryStream and reading it back when needed)?
just ran into thoughts while reading about .NET Stream objects..
any input/feedback is greatly appreciated.

Imran.
Nov 20 '05 #1
4 939
Hi Imran,

A memory stream is to replace a process that has to write and read to disk,
without the need of that disk (or an other hard media).

The memorystream exist only inside one application.

For the purpose you want to use it (inside an application), you can in my
opinion better use a whatever Array or Table. Because for that you will need
the same amount of memory, while you can access it on better ways than the
only streaming way with single memorystream.

I hope this helps?

Cor
why would one want to use a MemoryStream?
it basically creates a stream in memory to read/write data from/to memory - which we can accomplish with our regular objects as well. We could read
strings/bytes etc from files using the FileStream (or from network using
NetworkStream) into the relevant .NET object and work on it as long as we
wish. if needed to have the data in memory for future use, we can just leave the object hanging around as long as we want to make use of the data .
the only thing different i would think is that while objects within the
application basically stick to the address space that the OS assigns to the process for the application, the memorysteam is free to read/write from/to
memory thats outside the application scope. is this correct? if so, are
there any performance implications if we leave a large amount of data
hanging around in the application-specific memory as opposed to writing it
somewhere else in memory and reading it back when needed (consider reading a large text file into a stringbuilder and leaving it hanging around for the
entire application lifetime as opposed to writing it to memory using a
MemoryStream and reading it back when needed)?
just ran into thoughts while reading about .NET Stream objects..
any input/feedback is greatly appreciated.

Imran.

Nov 20 '05 #2
On Sun, 27 Jun 2004 19:18:55 -0400, Imran Koradia wrote:
why would one want to use a MemoryStream?
it basically creates a stream in memory to read/write data from/to memory -
which we can accomplish with our regular objects as well. We could read
strings/bytes etc from files using the FileStream (or from network using
NetworkStream) into the relevant .NET object and work on it as long as we
wish. if needed to have the data in memory for future use, we can just leave
the object hanging around as long as we want to make use of the data .
the only thing different i would think is that while objects within the
application basically stick to the address space that the OS assigns to the
process for the application, the memorysteam is free to read/write from/to
memory thats outside the application scope. is this correct? if so, are
there any performance implications if we leave a large amount of data
hanging around in the application-specific memory as opposed to writing it
somewhere else in memory and reading it back when needed (consider reading a
large text file into a stringbuilder and leaving it hanging around for the
entire application lifetime as opposed to writing it to memory using a
MemoryStream and reading it back when needed)?
just ran into thoughts while reading about .NET Stream objects..
any input/feedback is greatly appreciated.

Imran.


One place I've been known to use MemoryStream is in cloning serializable
objects. Write the serialized object to the memorystream, and then
deserialize the object from the stream. Much faster then writing to disk
:)

--
Tom Shelton [MVP]
Nov 20 '05 #3
Imran,
In addition to the other comments.
why would one want to use a MemoryStream? You would want to use a MemoryStream, when you need to use a MemoryStream.
We could read
strings/bytes etc from files using the FileStream (or from network using
NetworkStream) into the relevant .NET object and work on it as long as we
wish. A MemoryStream allows us to Write our strings/bytes to memory, then read
them later.
if needed to have the data in memory for future use, we can just leave
the object hanging around as long as we want to make use of the data . Correct!
the only thing different i would think is that while objects within the
application basically stick to the address space that the OS assigns to the process for the application, the memorysteam is free to read/write from/to
memory thats outside the application scope. is this correct? No. The MemoryStream is in your application address space.
if so, are
there any performance implications if we leave a large amount of data
hanging around in the application-specific memory as opposed to writing it
somewhere else in memory and reading it back when needed (...)? There are always performance implications of leaving large amounts of data
hanging around in memory!
(consider reading a
large text file into a stringbuilder and leaving it hanging around for the
entire application lifetime as opposed to writing it to memory using a
MemoryStream and reading it back when needed)? I would not read a large text file into a MemoryStream, I would read it
directly into a StringBuilder, String or other specific object that I needed
it in.
just ran into thoughts while reading about .NET Stream objects..
any input/feedback is greatly appreciated. You would use a MemoryStream anyplace you needed a temporary file! Rather
then creating a temporary file on disk, you can use a MemoryStream to create
a temporary file in memory.

As Tom suggests, you can use a MemoryStream to Clone an object during
serialization.

In addition to Cloning an object, I find a MemoryStream useful in Edit
Cut/Copy/Paste & Drag & Drop implementations.

A third example: I have a project where I am doing an XslTransform using the
Stream from an HttpWebResponse and transforming it into a MemoryStream, I
then take the MemoryStream and save it as a property on a message in an
Exchange Server. Note I could have used a StringWriter instead of the
MemoryStream in this case.

Hope this helps
Jay
"Imran Koradia" <no****@microsoft.com> wrote in message
news:eF***************@TK2MSFTNGP10.phx.gbl... why would one want to use a MemoryStream?
it basically creates a stream in memory to read/write data from/to memory - which we can accomplish with our regular objects as well. We could read
strings/bytes etc from files using the FileStream (or from network using
NetworkStream) into the relevant .NET object and work on it as long as we
wish. if needed to have the data in memory for future use, we can just leave the object hanging around as long as we want to make use of the data .
the only thing different i would think is that while objects within the
application basically stick to the address space that the OS assigns to the process for the application, the memorysteam is free to read/write from/to
memory thats outside the application scope. is this correct? if so, are
there any performance implications if we leave a large amount of data
hanging around in the application-specific memory as opposed to writing it
somewhere else in memory and reading it back when needed (consider reading a large text file into a stringbuilder and leaving it hanging around for the
entire application lifetime as opposed to writing it to memory using a
MemoryStream and reading it back when needed)?
just ran into thoughts while reading about .NET Stream objects..
any input/feedback is greatly appreciated.

Imran.

Nov 20 '05 #4
wow...that explains a lot. thanks all for the feedback. i really appreciate
that. i'll keep these pointers in mind.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Imran,
In addition to the other comments.
why would one want to use a MemoryStream? You would want to use a MemoryStream, when you need to use a MemoryStream.
We could read
strings/bytes etc from files using the FileStream (or from network using
NetworkStream) into the relevant .NET object and work on it as long as we wish.

A MemoryStream allows us to Write our strings/bytes to memory, then read
them later.
if needed to have the data in memory for future use, we can just leave
the object hanging around as long as we want to make use of the data .

Correct!
the only thing different i would think is that while objects within the
application basically stick to the address space that the OS assigns to

the
process for the application, the memorysteam is free to read/write from/to memory thats outside the application scope. is this correct?

No. The MemoryStream is in your application address space.
if so, are
there any performance implications if we leave a large amount of data
hanging around in the application-specific memory as opposed to writing it somewhere else in memory and reading it back when needed (...)?

There are always performance implications of leaving large amounts of data
hanging around in memory!
(consider reading a
large text file into a stringbuilder and leaving it hanging around for the entire application lifetime as opposed to writing it to memory using a
MemoryStream and reading it back when needed)?

I would not read a large text file into a MemoryStream, I would read it
directly into a StringBuilder, String or other specific object that I

needed it in.
just ran into thoughts while reading about .NET Stream objects..
any input/feedback is greatly appreciated. You would use a MemoryStream anyplace you needed a temporary file! Rather
then creating a temporary file on disk, you can use a MemoryStream to

create a temporary file in memory.

As Tom suggests, you can use a MemoryStream to Clone an object during
serialization.

In addition to Cloning an object, I find a MemoryStream useful in Edit
Cut/Copy/Paste & Drag & Drop implementations.

A third example: I have a project where I am doing an XslTransform using the Stream from an HttpWebResponse and transforming it into a MemoryStream, I
then take the MemoryStream and save it as a property on a message in an
Exchange Server. Note I could have used a StringWriter instead of the
MemoryStream in this case.

Hope this helps
Jay
"Imran Koradia" <no****@microsoft.com> wrote in message
news:eF***************@TK2MSFTNGP10.phx.gbl...
why would one want to use a MemoryStream?
it basically creates a stream in memory to read/write data from/to memory -
which we can accomplish with our regular objects as well. We could read
strings/bytes etc from files using the FileStream (or from network using
NetworkStream) into the relevant .NET object and work on it as long as we wish. if needed to have the data in memory for future use, we can just

leave
the object hanging around as long as we want to make use of the data .
the only thing different i would think is that while objects within the
application basically stick to the address space that the OS assigns to

the
process for the application, the memorysteam is free to read/write from/to memory thats outside the application scope. is this correct? if so, are
there any performance implications if we leave a large amount of data
hanging around in the application-specific memory as opposed to writing it somewhere else in memory and reading it back when needed (consider reading a
large text file into a stringbuilder and leaving it hanging around for

the entire application lifetime as opposed to writing it to memory using a
MemoryStream and reading it back when needed)?
just ran into thoughts while reading about .NET Stream objects..
any input/feedback is greatly appreciated.

Imran.


Nov 20 '05 #5

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

Similar topics

4
by: Thomas J Shea | last post by:
I wonder if it would be possible to create a hybrid OS that runs both Microsoft and *nix software. I mean. If Microsoft teamed up with Red Hat or BSD to make a unified OS that could run anything...
2
by: Ann | last post by:
I am newbie to VC++. Presently I am working on a Java project that requires integration with C API using JNI. When I run a sample project like HelloWorld.... Then HelloWorld.h get included and...
0
by: David Allison | last post by:
Foriegn Key Required - Yes - no wonder it didnt work. Now they tell me. -- Dave Allison
9
by: Salad | last post by:
The other day my friends were on the web ready to purchase some tickets on-line for a concert. There was a textbox to enter their e-mail address and another to enter a password. So they entered...
1
by: Muckey | last post by:
Hi group I developed a window control textbox that should only accept numeric input. I built the control by going to new -> project -> vb -> windows control library The code is ok. i added a...
8
by: Tom | last post by:
I was reading Bjourne's book and wonder about constructors? If I have a class template<class T> class Vector { public: explicit Vector(size_t n); } Does a default constructor get...
1
by: QuasiAnon | last post by:
(assuming i'm using correct terminology...) seems this draft isn't too old, nor too young? Syntax of CSS rules in HTML's "style" attribute W3C Working Draft 15 May 2002...
11
by: LurkB | last post by:
Hello, I wonder whether how MouseListener can be used to capture a mouse movement on LiNux screen . Thanks in Advance L
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.