Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast insert container

I need a container 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

like image 525
Simone Avatar asked Jan 22 '26 01:01

Simone


1 Answers

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.

like image 70
Darin Dimitrov Avatar answered Jan 23 '26 15:01

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!