Committing Byte Array to Disk

  • Thread starter Thread starter jwgoerlich
  • Start date Start date
J

jwgoerlich

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.Write(MB(i))
StreamWriter.Flush()
Next

Any recommendations on squeezing more performance?

J Wolfgang Goerlich
 
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.StartupPath & "\Status.dat",
OpenMode.Binary)
FilePut(fnum, StatusData)
FileClose(fnum)

To Open:
Dim fnum As Integer = FreeFile()
FileOpen(fnum, Application.StartupPath & "\Status.dat",
OpenMode.Binary)
FileGet(fnum, StatusData)
FileClose(fnum)
 
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.Write(MB(i))
StreamWriter.Flush()
Next

Any recommendations on squeezing more performance?

Close all other programs which have disk access.

Cor
 
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
 
Back
Top