我有一个文件,需要在创建新对象时序列化同一个类的多个对象.我无法将它们存储在数组中,因为我需要将对象创建的实例序列化它们.请帮我.
我试图用来MessagePack保存多个结构列表,因为我读到它的性能比BinaryFormatter序列化更好。
我想要做的是接收实时时间序列数据并定期将其保存(附加)到磁盘上,例如,如果列表的元素数为 100。我的问题是:
1)在这种情况下,序列化结构列表并将其异步保存到磁盘是否更好?
2) 如何使用 MessagePack 简单地将其保存到磁盘?
public struct struct_realTime
{
public int indexNum { get; set; }
public string currentTime { get; set; }
public string currentType { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<struct_realTime> list_temp = new List<struct_realTime>(100000);
for (int num=0; num < 100000; num++)
{
list_temp.Add(new struct_realTime
{
indexNum = 1,
currentTime = "time",
currentType = "type",
});
}
string filename = "file.bin";
using (var fileStream …Run Code Online (Sandbox Code Playgroud)