simple question: Streams
-
hi, i still dont understand the concept of "stream", more specifically: System.IO.Stream System.IO.MemoryStream Here's a code fragment in VB.NET: Dim HSBCWC As new Customer() HSBCWC.ID = 08346 HSBCWC.FirstName = "Paul" HSBCWC.LastName = "Bowie" ... Dim stream As MemoryStream() Dim serializer As New XmlSerializer( Customer.GetType() ) serializer.Serialize( stream, HSBCWC ) QUESTION 1: Why not serialize to a string as supposed to a MemoryStream? It would be much simpler rite? ... stream.Flush() QUESTION 2: I dont understand why we need to flush? flush what from what? I thought HSBCWC has already been "flushed" to stream? stream.Seek(0,SeekOrigin.Begin) however, I do understand why u need to Seek (rewind the stream). ... Dim reader As New StreamReader(stream) message.body = reader.ReadToEnd() stream.Close() SmptMail.Send(message) I'm a newbie and pretty confused why we need "streams" in general. help! X| SHAME
-
hi, i still dont understand the concept of "stream", more specifically: System.IO.Stream System.IO.MemoryStream Here's a code fragment in VB.NET: Dim HSBCWC As new Customer() HSBCWC.ID = 08346 HSBCWC.FirstName = "Paul" HSBCWC.LastName = "Bowie" ... Dim stream As MemoryStream() Dim serializer As New XmlSerializer( Customer.GetType() ) serializer.Serialize( stream, HSBCWC ) QUESTION 1: Why not serialize to a string as supposed to a MemoryStream? It would be much simpler rite? ... stream.Flush() QUESTION 2: I dont understand why we need to flush? flush what from what? I thought HSBCWC has already been "flushed" to stream? stream.Seek(0,SeekOrigin.Begin) however, I do understand why u need to Seek (rewind the stream). ... Dim reader As New StreamReader(stream) message.body = reader.ReadToEnd() stream.Close() SmptMail.Send(message) I'm a newbie and pretty confused why we need "streams" in general. help! X| SHAME
"The MemoryStream class creates streams that have memory as a backing store instead of a disk or a network connection." I thought MemoryStream is a memory object (data in RAM). So, "Flush" will flush this data (already in memory) to another memory location??? help! norm
-
"The MemoryStream class creates streams that have memory as a backing store instead of a disk or a network connection." I thought MemoryStream is a memory object (data in RAM). So, "Flush" will flush this data (already in memory) to another memory location??? help! norm
Streams are supposed to be a higher-level abstract concept. An example: If you make a compression routine that compress one file to another, it will do just it. But if you create a routine that compresses a input stream into a output stream you can use this routine in ,e.g., serial ports, sockets, HTTP, files, and even memory, without changing it. So, a memorystream is useful when you want to use a routine that does something in/from a stream but do not want to have a file writing/reading overhead. The flush method does nothing: it's there only to make the interface consistent. Concussus surgo. When struck I rise.
-
Streams are supposed to be a higher-level abstract concept. An example: If you make a compression routine that compress one file to another, it will do just it. But if you create a routine that compresses a input stream into a output stream you can use this routine in ,e.g., serial ports, sockets, HTTP, files, and even memory, without changing it. So, a memorystream is useful when you want to use a routine that does something in/from a stream but do not want to have a file writing/reading overhead. The flush method does nothing: it's there only to make the interface consistent. Concussus surgo. When struck I rise.
Thanx for the feedback first of all. (1) but in the code fragment that i showed earlier, why not Serialize to a "String" as opposed to a "MemoryStream" (2) Quote: "An example: If you make a compression routine that compress one file to another, it will do just it." what do u mean by "it will do just it"? norm