存放大物件

时间:2012-06-09 08:30:50

标签: c# serialization storage

存储大型物品的最佳方法是什么?就我而言,它就像树或链表。

我尝试了以下内容:

1)关系数据库

对树木结构不利。

2)文件db

我尝试了RavenDB但是当我调用SaveChanges方法时它引发了System.OutOfMemory异常

3).Net序列化

工作很慢

4)Protobuf

它无法反序列化List<List<>>类型,我不确定链接结构。

所以...?

4 个答案:

答案 0 :(得分:3)

你提到protobuf - 我经常使用protobuf-net与大小数百兆字节的对象,但是:它确实需要适当地写为DTO,理想情况下是树(不是双向图,尽管如此)在某些情况下支持使用。)

对于双向链表,这可能意味着:将“之前”链接标记为序列化,然后在后反序列化回调中进行修复,以正确设置“上一个”链接。通常很容易。

你是对的,因为它目前不支持嵌套列表。通过使用具有列表的东西的列表,这通常是微不足道的,但我很想让它隐含 - 即库应该能够模拟这个而不需要你改变你的模型。如果您对我这样做感兴趣,请告诉我。

如果你有一个你想序列化的模型的具体例子,并希望我提供指导,请告诉我 - 如果你不能在这里发布,那么我的电子邮件就在我的个人资料中。完全取决于你。

答案 1 :(得分:0)

您是否尝试过Json.NET并将结果存储在文件中?

答案 2 :(得分:0)

选项[2]:NOSQL(文档)数据库

我建议Cassandra


来自cassandra wiki

Cassandra's public API is based on Thrift, which offers no streaming abilities 
any value written or fetched has to fit in memory. This is inherent to Thrift's 
design and is therefore unlikely to change. So adding large object support to
Cassandra would need a special API that manually split the large objects up 
into pieces. A potential approach is described in http://issues.apache.org/jira/browse/CASSANDRA-265.    
As a workaround in the meantime, you can manually split files into chunks of whatever 
size you are comfortable with -- at least one person is using 64MB -- and making a file correspond 
to a row, with the chunks as column values.

所以,如果您的文件是&lt; 10MB你应该没问题,只要确保限制文件大小,或者将大文件分成块。

答案 3 :(得分:0)

CouchDb在这样的挑战中表现非常出色。

storing a tree in CouchDb

storing a tree in relational databases