C# Serialization is great if you want to store your complete object graph in one file. For example lets say we have object A that is reference by both objects B and C. If you serialize B and C into separate streams you end up with A serialized twice, once for each stream. Now if I had used one stream for B and C then A would only be serialized once. This is how standard serialization works in most languages including Java.
Unfortunately, this doesn't fit well for reading/writing game resources where you have a lot of objects referencing each other. I would like to be able to save the objects in separate files and then when I load an object it will load the other objects as well. For example, if I load object B it also loads object A from a separate file. Now, if I load object C that has a reference to object A as well it will be pointed to the existing loaded object A instead of loading it again.
Trying to do this with the existing System.Runtime.Serialization namepsace is pointless because it doesn't give you enough control over the serialization of an object. This has primarily to do with the object type information being serialized as well. I have some ideas on how to implement this that I'll share if I get them to work.
No comments:
Post a Comment