-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-System.Collectionsbacklog-cleanup-candidateAn inactive issue that has been marked for automated closure.An inactive issue that has been marked for automated closure.
Milestone
Description
ConcurrentDictionary enables enumerating the dictionary while other threads are modifying it, making it very useful in a variety of scenarios. But its GetEnumerator allocates an enumerator object. We can't change the return type of GetEnumerator, but we can at least expose an enumerator struct to enable enumeration without allocating.
Proposal:
namespace System.Collections.Concurrent
{
public class ConcurrentDictionary<TKey, TValue>
{
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator(); // existing
public struct Enumerator // new
{
public Enumerator(ConcurrentDictionary<TKey, TValue> dictionary);
public bool MoveNext();
public KeyValuePair<TKey, TValue> Current { get; }
}
}
}
Example usage:
private static ConcurrentDictionary<string, int> s_dict = new ConcurrentDictionary<string, int>();
...
var enumerator = new ConcurrentDictionary<string, int>.Enumerator(s_dict);
while (enumerator.MoveNext())
{
Use(enumerator.Current);
}
MendelMonteiro, theodorzoulias, friflo, MihaZupan, KorneiDontsov and 3 more
Metadata
Metadata
Assignees
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-System.Collectionsbacklog-cleanup-candidateAn inactive issue that has been marked for automated closure.An inactive issue that has been marked for automated closure.