BinaryFormatter for serialization

前端 未结 2 1635
春和景丽
春和景丽 2021-01-25 01:05

I am working on my own remote desktop C# program. I wondered if I could Serialize using BinaryFormatter an object of my own for example \"Packet\" that contains properties of B

2条回答
  •  生来不讨喜
    2021-01-25 01:31

    This is possible, but I discourage it. The BinaryFormatter algorithm is proprietary, so it will be very difficult to write non-.NET applications using such data. The format has changed in the past, and may change in the future, so it is unsafe to use it for persistent data you expect to open again in the future with a new .NET version. I think BinaryFormatter was originally designed for passing data between processes on one machine, not for persisting data.

    BinaryFormatter is inefficient for data that contains multiple properties because it requires deserializing the entire object to access any field. This is especially problematic if the data contains large data like images.

    If your data does not require random access, I suggest serializing it to a text format like JSON or XML. If the data is large, you should consider compressing the text-encoded data.

    If you require random-access to data you should investigate data stores like MySQL or SQLite.

提交回复
热议问题