Deep copying or serialization
Posted on 2009-12-19
OK, here is my problem, and what I have done so far. I need to be able to parse input data, and create a fairly complex object hierarchy from this data. Once the hierarchy is created a number of properties of these objects will be changed, then the objects need to be saved as a "template", and later be reloaded and used as a starting base for new data. The data I am working with is dynamic and there is no way to know beforehand it's structure; all parsing and object creation is done by following a rule set. So basically it works like this:
1.) Sample data is parsed, producing an object hierarchy that represents the sample data's structure, but does not actually contain any values.
2.) Properties are then manually set by the user. Now in essence we have a template customized by the user.
3.) Currently I am saving the entire object hierarchy by serializing the highest object in the chain, and writing the data to a file.
So far I have accomplished all this and it is working perfectly. My problem is that many copies of these templates will have to be created as a starting base, filled with actual data, and further processing performed. Performance is of the utmost importance, since tens of thousands of these templates will have to be created in a single run and this cycle will repeat itself many times during the day and night. The way I see it I have three options, but I am completely open to suggestions.:
Option 1> I can load these templates from a file every time I need to create a new copy, but I am relatively sure this would be the worst option for performance.
Option 2 > I can load the base template, and add deep copying ability to each of the objects, but since there are complex relationships between them, and the depth of the chain is variable, I am afraid that this might not be the most efficient way either.
Option 3> I can load the base template, store it in a memory stream, then deserialize it from memory each time a new object is created from this template. I am not sure if option this would even work, as I have not yet tested it. I just finished everything else.
Please keep in mind that performance is of paramount importance. Any thoughts, ideas, or suggestions would be greatly appreciated. Thanks.