G
Guest
I have an array of an array of doubles and need to save this as a single byte
array.
Then save this byte array as a BLOB to an SQL 2005 database.
Array allocation code shown below:
Array myArray =
Array.CreateInstance(System.Type.GetType("System.Double[]"), 3);
Double[] dblArray1 = new double[4] { 23.56, 24.56, 25.56, 26.56 };
Double[] dblArray2 = new double[4] { 33.56, 34.56, 35.56, 36.56 };
Double[] dblArray3 = new double[4] { 43.56, 44.56, 45.56, 46.56 };
// Place above three double arrays in an myArray
myArray.SetValue(dblArray1, 0);
myArray.SetValue(dblArray2, 1);
myArray.SetValue(dblArray3, 2);
I have tried serialize the myArray object however the byte array is almost
twice the length of the array of doubles:
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, dblArray1);
BinaryReader reader = new BinaryReader(stream);
reader.BaseStream.Position = 0;
byte[] inputBytes = reader.ReadBytes((int)reader.BaseStream.Length);
However the byte count of the byte array is almost doubled that of the array
of doubles.
inputBytes byte count is 175 should of been 96 bytes.
Does anyone know a better way to save an Array of an Array of doubles to a
byte array?
Thanks in advance,
Scott
array.
Then save this byte array as a BLOB to an SQL 2005 database.
Array allocation code shown below:
Array myArray =
Array.CreateInstance(System.Type.GetType("System.Double[]"), 3);
Double[] dblArray1 = new double[4] { 23.56, 24.56, 25.56, 26.56 };
Double[] dblArray2 = new double[4] { 33.56, 34.56, 35.56, 36.56 };
Double[] dblArray3 = new double[4] { 43.56, 44.56, 45.56, 46.56 };
// Place above three double arrays in an myArray
myArray.SetValue(dblArray1, 0);
myArray.SetValue(dblArray2, 1);
myArray.SetValue(dblArray3, 2);
I have tried serialize the myArray object however the byte array is almost
twice the length of the array of doubles:
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, dblArray1);
BinaryReader reader = new BinaryReader(stream);
reader.BaseStream.Position = 0;
byte[] inputBytes = reader.ReadBytes((int)reader.BaseStream.Length);
However the byte count of the byte array is almost doubled that of the array
of doubles.
inputBytes byte count is 175 should of been 96 bytes.
Does anyone know a better way to save an Array of an Array of doubles to a
byte array?
Thanks in advance,
Scott