by Anonymous » 10 Apr 2025, 00:40
Der Quellcode für die gleichzeitige Verfassung erwähnt die Möglichkeit, TalternateKey zu verwenden, was eine Ref -Struktur ist.
https://github.com/dotnet/runtime/blob/ ... tionary.cs
Auch nach einiger Suche fand ich andere Beispiele. Wie hier:
https://github.com/dotnet/runtime/blob/ ... ache.cs./p>
Code: Select all
#if NET9_0_OR_GREATER
private readonly ConcurrentDictionary.AlternateLookup _stringAltLookup;
public CoherentState()
{
_stringAltLookup = _stringEntries.GetAlternateLookup();
}
#endif
//...
#if NET9_0_OR_GREATER
internal bool TryGetValue(ReadOnlySpan key, [NotNullWhen(true)] out CacheEntry? entry)
=> _stringAltLookup.TryGetValue(key, out entry);
#endif
#if NET9_0_OR_GREATER
private readonly ConcurrentDictionary.AlternateLookup _stringAltLookup;
public CoherentState()
{
_stringAltLookup = _stringEntries.GetAlternateLookup();
}
#endif
Sollte ich ReadOnlySpan als Schlüssel verwenden, in gleichzeitiger Verfassung anstelle von String für eine bessere Leistung?
Der Quellcode für die gleichzeitige Verfassung erwähnt die Möglichkeit, TalternateKey zu verwenden, was eine Ref -Struktur ist.
https://github.com/dotnet/runtime/blob/main/src/libraries/system.collecies.concurrent/src/system/collections/concurrent/concurrentdictionary.cs
Auch nach einiger Suche fand ich andere Beispiele. Wie hier:
https://github.com/dotnet/runtime/blob/main/src/libraries/microsoft.extensions.caching.memory/src/Memorycache.cs./p>
[code]#if NET9_0_OR_GREATER
private readonly ConcurrentDictionary.AlternateLookup _stringAltLookup;
public CoherentState()
{
_stringAltLookup = _stringEntries.GetAlternateLookup();
}
#endif
//...
#if NET9_0_OR_GREATER
internal bool TryGetValue(ReadOnlySpan key, [NotNullWhen(true)] out CacheEntry? entry)
=> _stringAltLookup.TryGetValue(key, out entry);
#endif
#if NET9_0_OR_GREATER
private readonly ConcurrentDictionary.AlternateLookup _stringAltLookup;
public CoherentState()
{
_stringAltLookup = _stringEntries.GetAlternateLookup();
}
#endif
[/code]
Sollte ich ReadOnlySpan als Schlüssel verwenden, in gleichzeitiger Verfassung anstelle von String für eine bessere Leistung?