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. .NET (Core and Framework)
  4. reset a memorystream

reset a memorystream

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
5 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.
  • T Offline
    T Offline
    thebread
    wrote on last edited by
    #1

    hey folks, what is the fastest way to have a clean fresh System.IO.MemoryStream each time i write into it? one way is to make a ms.SetLength(0) before i write in to it. Another way is to create a new one each time. i think this two methods aren't very fast. is there another posibility to clear a stream? thanks, bernd

    G 1 Reply Last reply
    0
    • T thebread

      hey folks, what is the fastest way to have a clean fresh System.IO.MemoryStream each time i write into it? one way is to make a ms.SetLength(0) before i write in to it. Another way is to create a new one each time. i think this two methods aren't very fast. is there another posibility to clear a stream? thanks, bernd

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      No, there isn't. If you want something faster, perhaps you should use something other than MemoryStream. Why the need for speed?

      --- b { font-weight: normal; }

      T 1 Reply Last reply
      0
      • G Guffa

        No, there isn't. If you want something faster, perhaps you should use something other than MemoryStream. Why the need for speed?

        --- b { font-weight: normal; }

        T Offline
        T Offline
        thebread
        wrote on last edited by
        #3

        thanks guffa, speed is always nice to have ;-) and what's faster, setting the length to 0 or create a new one?

        G 1 Reply Last reply
        0
        • T thebread

          thanks guffa, speed is always nice to have ;-) and what's faster, setting the length to 0 or create a new one?

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          That depends. Setting the length to 0 should probably be faster than creating a new one, but the speed of that single action is not all that affects the speed of your application. A MemoryStream that is reset will probably handle memory allocations differently from a newly created one. I know too little about that difference, and especially too little about what your application is doing, to advice you in either direction. Don't do premature omtimization. You should always avoid anti-patterns (known bad solutions), but specific optimization should generally be put off until you know where and why you need it.

          --- b { font-weight: normal; }

          T 1 Reply Last reply
          0
          • G Guffa

            That depends. Setting the length to 0 should probably be faster than creating a new one, but the speed of that single action is not all that affects the speed of your application. A MemoryStream that is reset will probably handle memory allocations differently from a newly created one. I know too little about that difference, and especially too little about what your application is doing, to advice you in either direction. Don't do premature omtimization. You should always avoid anti-patterns (known bad solutions), but specific optimization should generally be put off until you know where and why you need it.

            --- b { font-weight: normal; }

            T Offline
            T Offline
            thebread
            wrote on last edited by
            #5

            i integrated ironPython in my application to ensure sccripting support. ironPython writes it's output into a stream. but you're right...currently everythings works fine and performace is till now no problem. thanks for your help!

            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