C# Programming
01-31-2010, 01:11 AM
Hello Guys,
Need some help from you guys.
I have Generic List having a Class object.
I have added around 3000000 items in the list
List lsTemp = new List ();
when i tried to Serialize the with binary formater it is working fine
but when I deserialize the List it takes a lot of time around 30 Seconds.
But when i fill the Generic List with any datatype like
List lsTemp = new List();
and follow the same procedure the speed difference is drastic the while thing deserializes in 1 -2 Seconds
My Class object is Declared Serializable.
I dont understand why it is serialzer is behaving like this.
Am i Missing something.
Here is the Sample Code :
List lsTemp = new List();
for(int i=0; i < 5000000;i++)
{
CTempClass oTemp = new CTempClass();
oTemp.ID = i;
lsTemp.Add(oTemp);
oTemp=null;
}
using (Stream stream = File.Open("c:\\data.bin", FileMode.CreateNew))
{
BinaryFormatter bin = new BinaryFormatter();
bin.Serialize(stream, lsTemp );
}
//this takes a lot of time
using (Stream stream = File.Open("c:\\data.bin", FileMode.Open))
{
BinaryFormatter bin = new BinaryFormatter();
var lsTemp1 = bin.Deserialize(stream);
}
here is the code of temp class
[Serializable]
public class CTempClass : ISerializable
{
// public int nId;
private ulong m_uCrc64;
public CTempClass ()
{
m_uCrc64 = 0;
}
//Deserialization constructor.
public CTempClass (SerializationInfo info, StreamingContext ctxt)
{
//Get the values from info and assign them to the appropriate properties
m_uCrc64 = info.GetUInt64("m_uCrc64");
}
//Serialization function.
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("m_uCrc64", m_uCrc64);
}
}
Can any one please tell me why it is taking so much of time.
Any suggestion will be a great help
abhinav
Need some help from you guys.
I have Generic List having a Class object.
I have added around 3000000 items in the list
List lsTemp = new List ();
when i tried to Serialize the with binary formater it is working fine
but when I deserialize the List it takes a lot of time around 30 Seconds.
But when i fill the Generic List with any datatype like
List lsTemp = new List();
and follow the same procedure the speed difference is drastic the while thing deserializes in 1 -2 Seconds
My Class object is Declared Serializable.
I dont understand why it is serialzer is behaving like this.
Am i Missing something.
Here is the Sample Code :
List lsTemp = new List();
for(int i=0; i < 5000000;i++)
{
CTempClass oTemp = new CTempClass();
oTemp.ID = i;
lsTemp.Add(oTemp);
oTemp=null;
}
using (Stream stream = File.Open("c:\\data.bin", FileMode.CreateNew))
{
BinaryFormatter bin = new BinaryFormatter();
bin.Serialize(stream, lsTemp );
}
//this takes a lot of time
using (Stream stream = File.Open("c:\\data.bin", FileMode.Open))
{
BinaryFormatter bin = new BinaryFormatter();
var lsTemp1 = bin.Deserialize(stream);
}
here is the code of temp class
[Serializable]
public class CTempClass : ISerializable
{
// public int nId;
private ulong m_uCrc64;
public CTempClass ()
{
m_uCrc64 = 0;
}
//Deserialization constructor.
public CTempClass (SerializationInfo info, StreamingContext ctxt)
{
//Get the values from info and assign them to the appropriate properties
m_uCrc64 = info.GetUInt64("m_uCrc64");
}
//Serialization function.
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("m_uCrc64", m_uCrc64);
}
}
Can any one please tell me why it is taking so much of time.
Any suggestion will be a great help
abhinav