You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of now we have return ref in C#. So I wish we would have more of it support on collection. And ConditionalWeakTable is one I think needed
It could be new class such as ConditionalWeakTableRef<TKey,TValue>. Just have it return reference when index. So we could attach struct to hold extension value
The text was updated successfully, but these errors were encountered:
Returning ref from collections can be dangerous if the storage for that ref might get removed or replaced, e.g. if a ref is returned to an array in the a list, and then the list grows and replaces the array such that the ref is now effectively invalidated, pointing into an array no longer associated with the list. That could happen implicitly as part of a conditional weak table, with the data getting dropped automatically when the key is no longer kept alive. Plus conditional weak tables are often used in a concurrent environment, where the underlying storage could get invalidated by other threads interacting with the collection. In short, I don't think this is something we should do.
So we could attach struct to hold extension value
If your concern is being able to store a struct in a conditional weak table, you can just wrap it in an object, e,.g. instead of making it a ConditionalWeakTable<TKey, TValue>, make it a ConditionalWeakTable<TKey, StrongBox<TValue>>.
As of now we have
return ref
in C#. So I wish we would have more of it support on collection. AndConditionalWeakTable
is one I think neededIt could be new class such as
ConditionalWeakTableRef<TKey,TValue>
. Just have it return reference when index. So we could attach struct to hold extension valueThe text was updated successfully, but these errors were encountered: