1

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)
        {
        }
UMR
  • 39
  • 1
  • 8
  • Looks like it would be much easier and faster to do it without serialization. – Ondrej Janacek Dec 19 '13 at 07:17
  • You must locate where is the delay. 1) on your actions ? 2) on the big data file that need deserialize... on the second case, use a different library, for example look at protobuf-net: https://code.google.com/p/protobuf-net/ – Aristos Dec 19 '13 at 07:22
  • Does this answer your question? [Fastest way to serialize and deserialize .NET objects](https://stackoverflow.com/questions/4143421/fastest-way-to-serialize-and-deserialize-net-objects) – StayOnTarget Sep 29 '22 at 16:36

1 Answers1

2

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

Community
  • 1
  • 1
Shanaka Rathnayaka
  • 2,462
  • 1
  • 23
  • 23