performance issue with serialization ?
From: Jean Bon (jean.bon_at_free.fr)
Date: 03/19/05
- Next message: Michael A. Covington: "Size and position of a PrintPreviewDialog"
- Previous message: web1110: "Re: Process question"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 19 Mar 2005 23:51:44 +0100
hello
I have an application which manages a tree of objects. each object
in the tree have a lot of references on other objects in the tree.
in the application, I serialize a lot this tree using a binary formatter.
there are a lot of classes in the application, I simplified the problem
with those two classes A and B :
[Serializable]
class A : ISerializable
{
private string s1, s2;
protected A(SerializationInfo info, StreamingContext ctx)
{
s1= info.GetString("s1");
s2= info.GetString("s2");
}
protected void GetObjectData(SerializationInfo info, StreamingContext ctx)
{
info.AddValue("s1", s1);
info.AddValue("s2", s2);
}
}
[Serializable]
class B : ISerializable
{
private int i1, i2;
private A parent;
protected B(SerializationInfo info, StreamingContext ctx)
{
i1= (int)info.GetInt32("is1");
i2= info.GetInt32("i2");
parent = (A) GetValue("parent", typeof(A));
}
protected void GetObjectData(SerializationInfo info, StreamingContext ctx)
{
info.AddValue("i1", i1);
info.AddValue("i2", i2);
info.AddValue("parent", parent);
}
}
if *a* is an instance of A and *a* is the root of the tree, I saw in the
debugger that when serializing this *a*, I go two times in GetObjectData
of A, one time when serializing *a* itself and another time when
serializing its reference in B. In my real application, GetObjectData
of *a* may be called more than 100 times, *a* is referenced by many
other objects...
questions :
-why so many calls to GetObjectData ? is it a bug in my application with
the way I implemented custom serialization ?
-I think I could not add *parent* in *info* when serializing and re-create
this reference in an OnDeserialization method that A would implement ?
something like that :
class A : ISerializable, IDeserializationCallback
{
//...
public void OnDeserialization(object sender)
{
son.SetParent(this);
}
}
what do you think of this kind of solution to avoid multiple calls to
GetObjectData because of object circular references ?
thanks for all
- Next message: Michael A. Covington: "Size and position of a PrintPreviewDialog"
- Previous message: web1110: "Re: Process question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|