最好的(免费)数据存储方式?如何更新文件系统? [英] Best (free) way to store data? How about updates to the file system?

查看:103
本文介绍了最好的(免费)数据存储方式?如何更新文件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何解决此问题有一个想法,但我想知道我的问题是否有更简单,更容易扩展的东西.

I have an idea for how to solve this problem, but I wanted to know if there's something easier and more extensible to my problem.

我正在处理的程序具有两种基本数据形式:图像以及与这些图像相关的信息.与图像相关的信息先前已存储在极其简单的JET数据库(四个表)中,事实证明,该数据库在存储字段中既缓慢又不完整.我们正在转向数据存储的新实现.考虑到所涉及的数据结构的简单性,我认为数据库是过大的.

The program I'm working on has two basic forms of data: images, and the information associated with those images. The information associated with the images has been previously stored in a JET database of extreme simplicity (four tables) which turned out to be both slow and incomplete in the stored fields. We're moving to a new implementation of data storage. Given the simplicity of the data structures involved, I was thinking that a database was overkill.

每个图像将具有其自身的信息(捕获参数),将是一组相互关联的图像的一部分(例如,在同一30分钟内拍摄),然后又是一个较大的组的一部分(总共是同一个人).现在,我将人们存储在具有唯一标识符的字典中.每个人都有一个不同图片组的列表,每个图片组都有一个图片组.所有这些类都是可序列化的,而我只是对字典进行序列化和反序列化.相当简单的东西.图片是分开存储的,因此字典的大小不会变成天文数字.

Each image will have information of it's own (capture parameters), will be part of a group of images which are interrelated (taken in the same thirty minute period, say), and then part of a larger group altogether (taken of the same person). Right now, I'm storing people in a dictionary with a unique identifier. Each person then has a List of the different groups of pictures, and each picture group has a List of pictures. All of these classes are serializable, and I'm just serializing and deserializing the dictionary. Fairly straightforward stuff. Images are stored separately, so that the dictionary doesn't become astronomical in size.

问题是:当我需要添加新的信息字段时会发生什么?是否有一种简单的方法来设置这些数据结构以应对将来的潜在修订?过去,我在C语言中处理此问题的方法是创建一个可序列化的结构,其中包含许多空字节(至少一个k)以用于将来的可扩展性,该结构中的一个字节指示版本.然后,当程序读取该结构时,它将基于大量的switch语句知道要使用哪种反序列化(旧版本可以读取新数据,因为无关的数据只会进入被忽略的字段中).

The problem is: what happens when I need to add new information fields? Is there an easy way to setup these data structures to account for potential future revisions? In the past, the way I'd handle this in C was to create a serializable struct with lots of empty bytes (at least a k) for future extensibility, with one of the bytes in the struct indicating the version. Then, when the program read the struct, it would know which deserialization to use based on a massive switch statement (and old versions could read new data, because extraneous data would just go into fields which are ignored).

C#中是否存在这样的方案?就像,如果我有一个包含一组String和Int对象的类,然后将另一个String对象添加到该结构中,如何从磁盘反序列化一个对象,然后向其中添加字符串?我是否需要辞职以拥有多个版本的数据类,并拥有一个采用反序列化流并根据存储在基类中的某些版本信息处理反序列化的工厂?还是像Dictionary这样的类是用于存储此类信息的理想选择,因为它会自动反序列化磁盘上的所有字段,并且如果添加了新字段,我就可以捕获异常并用空白的Strings和Ints替换那些值?

Does such a scheme exist in C#? Like, if I have a class that's a group of String and Int objects, and then I add another String object to the struct, how can I deserialize an object from disk, and then add the string to it? Do I need to resign myself to having multiple versions of the data classes, and a factory which takes a deserialization stream and handles deserialization based on some version information stored in a base class? Or is a class like Dictionary ideal for storing this kind of information, as it will deserialize all the fields on disk automatically, and if there are new fields added in, I can just catch exceptions and substitute in blank Strings and Ints for those values?

如果我使用字典方法,那么与文件读/写以及参数检索时间相关的速度有没有提高?我认为,如果一个类中只有字段,那么字段检索是即时的,但是在字典中,与该类相关的开销很小.

If I go with the dictionary approach, is there a speed hit associated with file read/writes as well as parameter retrieval times? I figure that if there's just fields in a class, then field retrieval is instant, but in a dictionary, there's some small overhead associated with that class.

谢谢!

推荐答案

此刻,我的大脑被炸掉了,所以我不确定我可以建议还是反对数据库,但是如果您正在寻找与版本无关的数据库,进行序列化,您会傻傻地至少不检查协议缓冲区.

My brain is fried at the moment, so I'm not sure I can advise for or against a database, but if you're looking for version-agnostic serialization, you'd be a fool to not at least check into Protocol Buffers.

以下是我了解的有关C#/.NET的实现的快速列表:

Here's a quick list of implementations I know about for C#/.NET:

  • protobuf-net
  • Proto#
  • jskeet's dotnet-protobufs

这篇关于最好的(免费)数据存储方式?如何更新文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆