| re: C# App: Binary Serialization File Size Allocation
When you serialize, two things happen:
1. The actual members are written to disk. If these are fixed-size value types, they should occupy the same amount of bytes each time.
2. Meta-data about your class is written to the serialization stream. As Plater said, the meta-data is used to determine the exact source object that needs to be re-created. This includes the assembly name, version and other reflection data. My opinion would be not to rely on that always being the same number of bytes. It probably would be the same if you never recompiled the assembly.
While the serialization attributes allow you to control which members are serialized or not, it will not be as easy to control what meta-data is written to your serialization stream.
Dantz, I think what you want to do is write only the member data to file (for example, your int field) and then on reconstruction, you are simply creating a new object and filling it with the data which was stored to file. Your code takes on the responsibility of knowing what object to create, rather than the serialization. To do so, you might add a "fixed-length" field which indicates the object type.
So you are "emulating" serialization, but you would not be using the built-in serialization libraries of .Net. Nor should you try to "override" the serialization methods. You need to decide if this work-around is what you want, but .Net serialization always needs the meta-data of the object it is dealing with.
|