我找到了这个引人注目的库,名为TeaFiles.NET。
我正在编写一个非常简单的控制台应用程序来测试它。
以下是代码:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting....");
string filename = String.Format("History_{0}.{1}.{2}.tea",
DateTime.Now.Year,
DateTime.Now.Month,
DateTime.Now.Day);
File.Delete(filename);
using (var tf = TeaFile<HistoryRow>.Create(filename))
{
var items = new List<HistoryRow>();
for (int i = 0; i < 1000; i++)
{
for (int k = 0; k < 100000; k++)
{
items.Add(new HistoryRow()
{
Flags = 192,
Name = "Name_" + i.ToString(CultureInfo.InvariantCulture),
Value = k,
Timestamp = DateTime.Now.AddTicks((long)i)
});
}
}
var sw = Stopwatch.StartNew();
Console.WriteLine("Initiate write...");
tf.Write(items);
sw.Stop();
Console.WriteLine("...completed write in {0} ms.", sw.ElapsedMilliseconds);
}
Console.ReadLine();
}
}
struct HistoryRow
{
public string Name;
public dynamic Value;
public Time Timestamp;
public int Flags;
}
这应该非常简单。相反,它在Create()调用时出错,并出现以下错误:
"The specified Type must be a struct containing no references".
我真的不知道从哪里开始排除故障......
答案 0 :(得分:3)
TeaFiles提供对时间序列数据的快速读/写访问。鉴于该库需要struct
包含@dtb描述为blittable types的内容,这应该有效:
[StructLayout(LayoutKind.Sequential, Pack=1)]
struct HistoryRow
{
public char[16] Name;
public double Value;
public Time Timestamp;
public int Flags;
}
请注意,在存储时间数据系列时,通常不会存储带有值的描述,该值是已具有名称的列中的许多值之一。