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. C#
  4. How to clear MemoryStream ?

How to clear MemoryStream ?

Scheduled Pinned Locked Moved C#
performancehelptutorialquestion
7 Posts 5 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.
  • S Offline
    S Offline
    Saikek
    wrote on last edited by
    #1

    Greetings Comrades, Does anybody knows how to clear Stream?

    Stream memoryStream = new MemoryStream();
    ...
    memoryStream.Flush() - does nothing
    memoryStream.SetLength(0) - calls AccessViolationException ("memory is corrupt")

    Any help will be just fine. Thanks!!!

    One nation - underground

    B M 2 Replies Last reply
    0
    • S Saikek

      Greetings Comrades, Does anybody knows how to clear Stream?

      Stream memoryStream = new MemoryStream();
      ...
      memoryStream.Flush() - does nothing
      memoryStream.SetLength(0) - calls AccessViolationException ("memory is corrupt")

      Any help will be just fine. Thanks!!!

      One nation - underground

      B Offline
      B Offline
      Bassam Saoud
      wrote on last edited by
      #2

      you close and dispose it.

      1 Reply Last reply
      0
      • S Saikek

        Greetings Comrades, Does anybody knows how to clear Stream?

        Stream memoryStream = new MemoryStream();
        ...
        memoryStream.Flush() - does nothing
        memoryStream.SetLength(0) - calls AccessViolationException ("memory is corrupt")

        Any help will be just fine. Thanks!!!

        One nation - underground

        M Offline
        M Offline
        Mohammad Dayyan
        wrote on last edited by
        #3

        Did you use this :

        memoryStream.Dispose();

        S 1 Reply Last reply
        0
        • M Mohammad Dayyan

          Did you use this :

          memoryStream.Dispose();

          S Offline
          S Offline
          Saikek
          wrote on last edited by
          #4

          But in this case am I able to continue using MemoryStream ?

          One nation - underground

          D 1 Reply Last reply
          0
          • S Saikek

            But in this case am I able to continue using MemoryStream ?

            One nation - underground

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Nope. The only way to clear it out is to Seek to position 0 and write 0's to every known position. Depending on the size of the Stream, it's porobably going to be faster, or at least easier, to just kill the existing stream and create a new one.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            S 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Nope. The only way to clear it out is to Seek to position 0 and write 0's to every known position. Depending on the size of the Stream, it's porobably going to be faster, or at least easier, to just kill the existing stream and create a new one.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              S Offline
              S Offline
              Saikek
              wrote on last edited by
              #6

              Thank you.

              One nation - underground

              S 1 Reply Last reply
              0
              • S Saikek

                Thank you.

                One nation - underground

                S Offline
                S Offline
                Santhosh Thakur
                wrote on last edited by
                #7

                Try this out

                MemoryStream ms = new MemoryStream();
                .......
                ......

                ms.SetLength(0);
                ms.Position = 0;

                Hope this Works!!! :)

                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