Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. simple question: Streams

simple question: Streams

Scheduled Pinned Locked Moved Visual Basic
questioncsharpsaleshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devvvy
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • D devvvy

      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

      D Offline
      D Offline
      devvvy
      wrote on last edited by
      #2

      "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

      D 1 Reply Last reply
      0
      • D devvvy

        "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

        D Offline
        D Offline
        Daniel Turini
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • D Daniel Turini

          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.

          D Offline
          D Offline
          devvvy
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups