简体   繁体   English

C#\\避免内存不足异常

[英]C# \ avoid out of memory exception

assume I have a class with List<T> member. 假设我有一个List<T>成员的类。 Let's say I'm not sure how many items will be pushed inside (but I don't want to do it as blocked list) - and this list contains sliding window of items from the last 24 hours (and I access it with LINQ queries). 假设我不确定要推入多少项目(但我不想将其作为阻止列表)-并且该列表包含最近24小时内的滑动项目窗口(并且我使用LINQ查询进行访问) )。

Is there a neat way to tell the list to serialize itself to some disk file to avoid out of memory and desiralize itself when items are removed again from the list? 是否有一种灵巧的方法告诉列表将自身序列化到某个磁盘文件,从而避免内存不足并在再次从列表中删除项目时对自身进行反序列化? (File Stream or something) (文件流或其他内容)

Or do I need to write the mechanism myself? 还是我需要自己编写该机制?

通常,这就是您要使用数据库的目的。

您可以使用XML Searialization将具有属性的整个类作为xml存储到数据库(如果使用MS SQL,则为xml类型)或xml文件中,然后在需要时反序列化。

不,没有这种方法,您对LINQ可访问性的要求甚至更多。

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

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