Home All Groups Group Topic Archive Search About

Committing Byte Array to Disk

Author
22 Mar 2006 3:56 PM
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

Author
22 Mar 2006 4:26 PM
guy
suggest you move the StreamWriter.Flush outside the loop

Show quoteHide quote
"jwgoerl***@gmail.com" wrote:

> 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
>
>
Author
22 Mar 2006 5:01 PM
Rocky
Use BinaryWriter instead.

bw.write(MB)



Show quoteHide quote
"guy" <g**@discussions.microsoft.com> wrote in message
news:2D04CF28-BE5C-462F-B389-68133E2515BF@microsoft.com...
> suggest you move the StreamWriter.Flush outside the loop
>
> "jwgoerl***@gmail.com" wrote:
>
>> 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
>>
>>
Author
22 Mar 2006 5:24 PM
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)
Author
22 Mar 2006 5:50 PM
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
Author
22 Mar 2006 7:08 PM
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