H
Hilton
Hi,
I have arrays of ints, float, or doubles etc (e.g. int[], float[], or
double[]), how can I use 'fwrite' and 'fread' to write the array to and read
the array from a file in C# (CF)? I'd prefer not to do any copying etc, so
I'm looking for something like this:
double[] x = new double[]{1.2, 2.3, Math.PI};
unsafe
{
fixed (double *doublePtr = &x[0])
{
byte *ptr = (byte *) doublePtr;
FileStream fs = new FileStream ("\\double.dat",
FileMode.Create);
fs.Write (ptr, 0, x.Length * sizeof(double));
fs.Close ();
}
}
And then have code on the read side doing something like "double[] ptr =
new...; fread (ptr)" (at least the equivalent in C#).
BTW: If you have a non-unsafe solution, that would be excellent!!!
Thanks,
Hilton
I have arrays of ints, float, or doubles etc (e.g. int[], float[], or
double[]), how can I use 'fwrite' and 'fread' to write the array to and read
the array from a file in C# (CF)? I'd prefer not to do any copying etc, so
I'm looking for something like this:
double[] x = new double[]{1.2, 2.3, Math.PI};
unsafe
{
fixed (double *doublePtr = &x[0])
{
byte *ptr = (byte *) doublePtr;
FileStream fs = new FileStream ("\\double.dat",
FileMode.Create);
fs.Write (ptr, 0, x.Length * sizeof(double));
fs.Close ();
}
}
And then have code on the read side doing something like "double[] ptr =
new...; fread (ptr)" (at least the equivalent in C#).
BTW: If you have a non-unsafe solution, that would be excellent!!!
Thanks,
Hilton