Reputation: 39
I am trying to do Serialization and Deserialization for Dictionaries in C#. Problem is that, when i do Deserialization, it take 3-4 mins. Size of Text file is 4.3 MB Here is my Code .. Please help me out.
[Serializable]
public class WordTag
{
public String Word, Tag;
public double prob;
public WordTag()
{ }
public WordTag(String W, String T)
{
Word = W;
Tag = T;
}
[Serializable]
public class EqualityComparer : IEqualityComparer<WordTag>
{
public bool Equals(WordTag x, WordTag y)
{
return x.Word == y.Word && x.Tag == y.Tag;
}
public int GetHashCode(WordTag x)
{
return base.GetHashCode();
}
}
}
.....................
try
{
using (Stream stream = File.Open("e:\\WordTagFreq.txt", FileMode.Open))
{
BinaryFormatter bin = new BinaryFormatter();
WordTagDic.Clear();
WordTagDic = (Dictionary<WordTag, int>)bin.Deserialize(stream);
}
}
catch (IOException)
{
}
Upvotes: 1
Views: 2944
Reputation: 2682
Same question is already answered.
Fastest way to serialize and deserialize .NET objects
for further information http://www.codeproject.com/Articles/37609/Serialize-and-Deserialize-Objects-as-XML-using-Gen
Upvotes: 2