Friday, May 17, 2013

serialization with BinaryFormatter

This is very crazy. I thought BinaryFormatter.serialize will do the magic and makes my life easier. Apparently, it is the opposite. The binary formatter does something crazy and I can't predict when it goes crazy. The result is the transfer data is veryy incredibly slowww.. From my experience, you can do serialize object using binaryformatter only for general type like int, byte, float, String, etc (Im not sure about enum)

Now here is the example:
// [Serializable]   // I could put here too the result still the same
struct DataPos
{
   float posX;
   float posY;
   float rot;
};

[Serializable]
struct ShipData
{
   // this is just enumeration for type
   eType type;

   // here I was trying only data position
   DataPos datapos;
}

The binaryformatter DOES NOT WORK WELL on this structure. I tried to put padding too in the enumeration and same thing. It doesn't say it is illegal. It just slows the transfer data. It takes 3 days to debug this shit.

Here after I change the data into this structure

[Serializable]
struct ShipData
{
   // this is just enumeration for type
   eType type;
   
   // not using the struct
   float posX;
   float posY;
   float rot;
}

everything goes well. This is really stupidd.. The BinaryFormatter should tell he can't serialize that if he can't. Not just by keep silent and let the programmer debug himself.

No comments:

Post a Comment