Hi
I am serializing a dataset using a binary formatter as follows:
IFormatter formater = new BinaryFormatter ();
formatter.Seria lize(stream, ds); // ds=DataSet, stream=MemorySt ream
....
DataSet ds2 = (DataSet)format ter2.Deserializ e(stream2);
For the size of my DataSet, its taking 0.8 seconds to serialize and 2.3
seconds to deserialize.
After reading some previous archive messages, I decided to try some manual
binary serialization using a custom DataSet (myDataSet). I have slightly
improved on my deserialization time (now takes 0.9 seconds) but my
serialzation has gone mad (takes 10 seconds). All this time is being spent
after the myDataSet.GetOb jectData method. What is hapenning after this
method?
any advice on how to improve this time would be appreciated.
thanks
Code
------
IFormatter formater = new BinaryFormatter ();
formatter.Seria lize(stream, myds); // myds=myDataSet, stream=MemorySt ream
....
myDataSet myds2 = (myDataSet)form atter2.Deserial ize(stream2);
myDataSet class
----------------------
[Serializable]
public class myDataSet : DataSet, ISerializable
{
public myDataSet() : base()
{}
public myDataSet(strin g name) : base(name)
{}
protected myDataSet(Seria lizationInfo sinfo, StreamingContex t context)
{
// Extract from the serialization info
ArrayList tables = new ArrayList();
tables = (ArrayList) sinfo.GetValue( "Tables", typeof(ArrayLis t));
// foreach table name in tables create a DataTable and add to table
collection
for(int i=0;i<tables.Co unt; i++)
{
string tableName = (string)tables[i];
DataTable dt = new DataTable(table Name);
ArrayList colNames = new ArrayList();
ArrayList colTypes = new ArrayList();
ArrayList dataRows = new ArrayList();
colNames = (ArrayList) sinfo.GetValue( "ColNames_"+tab leName,
typeof(ArrayLis t));
colTypes = (ArrayList) sinfo.GetValue( "ColTypes_"+tab leName,
typeof(ArrayLis t));
dataRows = (ArrayList) sinfo.GetValue( "DataRows_"+tab leName,
typeof(ArrayLis t));
// Add columns
for(int iCol=0; iCol<colNames.C ount; iCol++)
{
DataColumn col = new DataColumn(colN ames[iCol].ToString(),
Type.GetType(co lTypes[iCol].ToString() ));
dt.Columns.Add( col);
}
// Add rows
for(int iRows=0; iRows<dataRows. Count; iRows++)
{
DataRow row = dt.NewRow();
row.ItemArray = (object[]) dataRows[iRows];
dt.Rows.Add(row );
}
this.AcceptChan ges();
// Add table to Tables collection
this.Tables.Add (dt);
}
void ISerializable.G etObjectData(Se rializationInfo sinfo,
StreamingContex t context)
{
// Add arrays
ArrayList tables = new ArrayList();
foreach(DataTab le dt in this.Tables)
{
ArrayList colNames = new ArrayList();
ArrayList colTypes = new ArrayList();
ArrayList dataRows = new ArrayList();
string tableName = dt.TableName ;
// Insert the table name into worker array
tables.Add(tabl eName);
// Insert column information (names and types) into worker arrays
for(int iCols=0; iCols<dt.Column s.Count; iCols++)
{
DataColumn Col = dt.Columns[iCols];
colNames.Add(Co l.ColumnName);
colTypes.Add(Co l.DataType.Full Name);
}
for(int iRows=0; iRows<dt.Rows.C ount; iRows++)
{
dataRows.Add(dt .Rows[iRows].ItemArray);
}
// Add arrays to the serialization info structure
sinfo.AddValue( "ColNames_"+tab leName, colNames);
sinfo.AddValue( "ColTypes_"+tab leName, colTypes);
sinfo.AddValue( "DataRows_"+tab leName, dataRows);
}
sinfo.AddValue( "Tables", tables);
}
}