"Tales Normando" <ta*****@bol.com.br> wrote in message
news:ea**************@TK2MSFTNGP11.phx.gbl...
The title says it all. Anyone?
I'm not sure you want the _very_ fastest way.
The array of doubles is sitting on the managed heap. To be written to a
file the doubles must be converted to bytes. BitConverter can do this one
double at a time, but this requires copying each double to the stack,
copying it to a new 4-byte array and writing that array to disk. This
generates many more instructions and more memory copying than would be
necessary in, say, C. But CPU speeds and memory speeds are so much faster
than disk IO speeds that the amount of memory copying or looping in code
rarely matters much. Who really cares if your CPU is at 1% as opposed to 5%
when writing to disk?
The very fastest way to do this would probably to open a file mapping
against the target file, get an IntPtr pointer to the desired offset in the
file, and use System.Runtime.InteropServices.Marshal.Copy to copy the array
of doubles to the IntPtr. This would write the array to file with no
looping in managed code absolutely no intermediate copying. But that's a
giant hastle and requires a ton of code permissions.
But the easy, safe way performs just fine for almost all purposes:
Dim f As New System.IO.FileStream("out.bin", IO.FileMode.OpenOrCreate,
IO.FileAccess.Write)
Dim br As New System.IO.BinaryWriter(f)
For Each d As Double In dd
br.Write(d)
Next
br.Close()
f.Close()
David