开发者

Fast insert container

I need a c开发者_如何学JAVAontainer where insert is fast and thread-safe, because I plan to use it inside a Parallel.for_each instance.

Once in a while, I will scan said container and remove every items contained.

What's the best choice given those costraints?

Thanks


You could use a ConcurrentBag<T>. Basically the System.Collections.Concurrent namespace is worth checking. If you have unique keys, a ConcurrentDictionary<TKey, TValue> would be a great choice as it provides you a very fast access to elements given a key.


There are a bunch of concurrent collections in .NET 4.0: dictionary, queue, etc. See http://msdn.microsoft.com/en-us/library/dd997305.aspx


try ConcurrentBag - it is thread-safe and very fast since most operations are implemented lock-free... there are also ConcurrentDictionary etc. so I am not sure which features you exactly need.


Linked List. That has fast insertion, though I'm not sure if a threadsafe version exists in .NET

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜