gpt4 book ai didi

c# - 巨大的列表保存在小文件中

转载 作者:行者123 更新时间:2023-11-30 18:52:29 26 4
gpt4 key购买 nike

我正在尝试在文件中保存大量 double 列表。现在它看起来像这样:

try{
FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.OpenOrCreate);
using(BinaryWriter binaryWriter = new BinaryWriter(fs))
{
foreach (double value in bigData)
{
binaryWriter.Write(value);
}
binaryWriter.Close();
}
fs.Close();
} catch(System.IO.FileNotFoundException)
{
MessageBox.Show("Unexpected save error\n", "Save error!", MessageBoxButtons.OK);
}

bigData is a List<double>在测试用例中,它包含 200 万个对象。

保存的文件大约有 15MB,我认为这对于二进制数据来说已经相当多了。有没有人知道我怎样才能让它更小?

另外,请记住,我需要在保存后打开此文件 - 但这是通过另一种方法完成的。

最佳答案

double 是 8 bytes long ,所以 200 万乘以 8 大约是 16MB。看起来不错。

关于c# - 巨大的列表<double>保存在小文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20685053/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com