C#字典表现 [英] C# Dictionary Performance
问题描述
我正在使用Dictionary来存储数据,并将缓存它。我想避免服务器内存问题,并且通过限制字典大小或条目数量来限制字典大小,具有良好的性能。
最好的方法是什么?还有另外一个类,我应该考虑一个词典吗?
p>
您可以查看通过查看 System.Collections.Generic 命名空间
他们是一个非常好的帖子,描述了MSDN上所有大部分收集类的优缺点。
如果您对这些类提供的内容不满意,您可以去自己的收藏类或设计一个自定义词典
你的自我。
您将需要继承自己的字典fron IDictionary接口和其他类/接口,或者可以从头开始写全部。 >
以下是 Dictionary class 在MSDN
[SerializableAttribute]
[ComVisibleAttribute(false) ]
public class Dictionary< TKey,TValue> :IDictionary< TKey,TValue>
ICollection< KeyValuePair> TKey,TValue>>
IEnumerable< KeyValuePair< TKey,TValue>>
IDictionary,ICollection,IEnumerable,
ISerializable,IDeserializationCallback
I am using a Dictionary to store data, and will be caching it. I would like to avoid server memory issues, and have good performance by limiting the size of the Dictionary<>, either in size or number of entries.
What is the best method of doing this? Is there another class I should be considering other than a Dictionary?
There are several other classes you can select from like
you can review the options by looking at System.Collections.Generic Namespace.
Their is a very good post, describibg pros and cons for all most of the collection classes at MSDN
If you are not satisfied by what these classes are provide, you can go for your own collection class or design a custom Dictionary
your self.
you will need to inherit your custom dictionary fron IDictionary Interface and other classes / interfaces or may write all from scratch.
Here is the signature for Dictionary class at MSDN
[SerializableAttribute]
[ComVisibleAttribute(false)]
public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>,
ICollection<KeyValuePair<TKey, TValue>>,
IEnumerable<KeyValuePair<TKey, TValue>>,
IDictionary, ICollection, IEnumerable,
ISerializable, IDeserializationCallback
这篇关于C#字典表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!