Committing Byte Array to Disk

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jwgoerlich@gmail.com

    #1

    Committing Byte Array to Disk

    What is the fastest way of writing a Byte array to disk? I have a 512
    MB array in memory. I am writing to a 10K RPM drive, and have ample CPU
    and RAM. I need to write as much data as possible, as fast as possible.


    Currently, I am using the StreamWriter. I am not getting anywhere near
    the thru put I would expect. My code is something like:

    For i = 0 To (MB.Length - 1)
    StreamWriter.Wr ite(MB(i))
    StreamWriter.Fl ush()
    Next

    Any recommendations on squeezing more performance?

    J Wolfgang Goerlich

  • guy

    #2
    RE: Committing Byte Array to Disk

    suggest you move the StreamWriter.Fl ush outside the loop

    "jwgoerlich@gma il.com" wrote:
    [color=blue]
    > What is the fastest way of writing a Byte array to disk? I have a 512
    > MB array in memory. I am writing to a 10K RPM drive, and have ample CPU
    > and RAM. I need to write as much data as possible, as fast as possible.
    >
    >
    > Currently, I am using the StreamWriter. I am not getting anywhere near
    > the thru put I would expect. My code is something like:
    >
    > For i = 0 To (MB.Length - 1)
    > StreamWriter.Wr ite(MB(i))
    > StreamWriter.Fl ush()
    > Next
    >
    > Any recommendations on squeezing more performance?
    >
    > J Wolfgang Goerlich
    >
    >[/color]

    Comment

    • Rocky

      #3
      Re: Committing Byte Array to Disk

      Use BinaryWriter instead.

      bw.write(MB)



      "guy" <guy@discussion s.microsoft.com > wrote in message
      news:2D04CF28-BE5C-462F-B389-68133E2515BF@mi crosoft.com...[color=blue]
      > suggest you move the StreamWriter.Fl ush outside the loop
      >
      > "jwgoerlich@gma il.com" wrote:
      >[color=green]
      >> What is the fastest way of writing a Byte array to disk? I have a 512
      >> MB array in memory. I am writing to a 10K RPM drive, and have ample CPU
      >> and RAM. I need to write as much data as possible, as fast as possible.
      >>
      >>
      >> Currently, I am using the StreamWriter. I am not getting anywhere near
      >> the thru put I would expect. My code is something like:
      >>
      >> For i = 0 To (MB.Length - 1)
      >> StreamWriter.Wr ite(MB(i))
      >> StreamWriter.Fl ush()
      >> Next
      >>
      >> Any recommendations on squeezing more performance?
      >>
      >> J Wolfgang Goerlich
      >>
      >>[/color][/color]


      Comment

      • knarfm@speakeasy.net

        #4
        Re: Committing Byte Array to Disk

        Try writing the whole array at one time.
        I am not sure if it is faster but it works for me.

        Public StatusData(255) As Byte

        To Save:
        Dim fnum As Integer = FreeFile()
        FileOpen(fnum, Application.Sta rtupPath & "\Status.da t",
        OpenMode.Binary )
        FilePut(fnum, StatusData)
        FileClose(fnum)

        To Open:
        Dim fnum As Integer = FreeFile()
        FileOpen(fnum, Application.Sta rtupPath & "\Status.da t",
        OpenMode.Binary )
        FileGet(fnum, StatusData)
        FileClose(fnum)

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Committing Byte Array to Disk

          >[color=blue]
          >
          > Currently, I am using the StreamWriter. I am not getting anywhere near
          > the thru put I would expect. My code is something like:
          >
          > For i = 0 To (MB.Length - 1)
          > StreamWriter.Wr ite(MB(i))
          > StreamWriter.Fl ush()
          > Next
          >
          > Any recommendations on squeezing more performance?
          >[/color]

          Close all other programs which have disk access.

          Cor


          Comment

          • jwgoerlich@gmail.com

            #6
            Re: Committing Byte Array to Disk

            Much obliged for all the help! I am getting closer. StreamWriter takes
            around 60 minutes. FilePut takes about two minutes (and really uses the
            CPU!). BinaryWriter takes from 30-60 seconds. This is quite a
            performance boost.

            Yet, even at 30-seconds or 136 Mb/s, I am getting around half the thru
            put from the disks that I expected. I suspect it is time to dig into
            this from a hardware perspective.

            Thanks again,

            J Wolfgang Goerlich

            Comment

            Working...