Committing Byte Array to Disk

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
 
K

knarfm

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)
 
C

Cor Ligthert [MVP]

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
 
J

jwgoerlich

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top