简体   繁体   English

在C#中将大型双精度数组保存为文件的最有效方法

[英]Most efficient way to save large double arrays as files in C#

I'm writing a program that is reading data from .dat files into double[,,] arrays, calculates some stuff and needs to write the arrays into a file to save them for a later usage. 我正在编写一个程序,该程序将从.dat文件中读取数据到double [,,]数组中,计算一些内容,需要将数组写入文件中以保存它们以备后用。

These arrays can have up to [64x64x150000] elements which forces me to already load those files in small parts into the program to make use of them (otherwise the MemoryException is called). 这些数组最多可以包含[64x64x150000]个元素,这迫使我已经将这些文件分成小部分加载到程序中以使用它们(否则调用MemoryException)。 Until now I used textfiles to save smaller arrays on my harddisk but saving a [64x64x150000] array step by step fills up above >6GB per file at the end which is quiet a lot when you have to work with a lot of those .dat-files and have pretty much to keep all the .txt-files. 到目前为止,我一直使用文本文件将较小的数组保存在硬盘上,但逐步保存[64x64x150000]数组会在每个文件最后占用大于6GB的空间,当您必须处理大量.dat-时,这非常安静。文件,并且几乎可以保留所有.txt文件。

So I would like to know if any other filetype saves some harddisk space or if there is another possibility to save those arrays outside of my program for a later usage with less harddisk space requirement. 因此,我想知道是否还有其他文件类型可以节省一些硬盘空间,或者是否还有其他可能性可以将这些数组保存在程序之外,以供以后使用而对硬盘空间的需求较少。

(I need to be able to exchange the files between different computers). (我需要能够在不同计算机之间交换文件)。

(8 B/double * (64 * 64 * 150000) double) / (10 9 B/GB) = 5.6 GB (8 B /双*(64 * 64 * 150000)双)/(10 9 B / GB)= 5.6 GB

So unless you either reduce to a lower precision (floats) or perform some kind of compression, you'll need 5.6 GB to store all those doubles. 因此,除非您降低到较低的精度(浮点数)或执行某种压缩,否则将需要5.6 GB来存储所有这些双精度数。 Reducing to floats would take 2.8 GB per file. 减少到浮动将占用每个文件2.8 GB。

For each of the 64 * 64 vectors of length 150000, you may be able to perform a signal compression (depending on what the data looks like). 对于长度为150000的64 * 64个向量中的每一个,您都可以执行信号压缩(取决于数据的样子)。 That's a broad topic, so without knowing more all I can give you is a starting point: Signal compression . 那是一个广泛的话题,因此,在不了解更多信息的情况下,我只能给您一个起点: 信号压缩

Either compression, or try Binary Serialization . 压缩或尝试Binary Serialization A double can take up dozens of bytes in text, particularly depending on your encoding (1-2 per digit). 双精度文本可能占用数十个字节的文本,特别是取决于您的编码(每位1-2)。 In binary, each one is exactly 8 bytes (+ however much overhead for bookkeeping, probably minimal). 以二进制形式,每个字节正好是8个字节(但是,簿记的开销很大,可能很小)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM