Brian Richards wrote:
[color=blue]
> I have an object that I'm serializing (binary) that contains other
> internal objects that are also serialized. The Object contains two
> other member objects (let's call them source, and depend) one of
> which has a state that depends value is derived from source. My
> question is (if this can be generalized) is faster/better to
> serialize both objects or to only serialize state and then during
> deserialization create depend from source.
>
> Option 1:
>
> [Serializable()]
> public class Foo
> {
> object source;
>
> object depend;
>
> protected Foo(SerializationInfo info, StreamingContext context) :
> base(info, context)
> {
> }
> }
> Option 2:
> [Serializable()]
> public class Foo
> {
> object source;
>
> [field:NonSerialized()]
> object depend;
>
> protected Foo(SerializationInfo info, StreamingContext context) :
> base(info, context)
> {
> depend = new depend();
> depend.State = source.Info;
>
> }
> }[/color]
Deserializing is always slower than simply re-creating the objects by
hand and filling in some data because the code deserializing has to use
is very complex and not straight forward simple as your option2, plus
data has to be interpreted, although the binary formatter uses some
shortcuts to get a blob quickly re-instantiated as an object.
FB
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------