.NET has 4 built-in dictionary/map types:
- Hashtable
- Dictionary
- ConcurrentDictionary
- ImmutableDictionary
Thereβs no guidance on when to use what, mostly individual documentation on each implementation.
#dotnet
- Hashtable
- Dictionary
- ConcurrentDictionary
- ImmutableDictionary
Thereβs no guidance on when to use what, mostly individual documentation on each implementation.
#dotnet
ConcurrentDictionary - Good read speed even in the face of concurrency, but itβs a heavyweight object to create and slower to update.
Dictionary with lock - Poor read speed lightweight to create and βmediumβ update speed.
Dictionary with lock - Poor read speed lightweight to create and βmediumβ update speed.
Dictionary as immutable object - best read speed and lightweight to create but heavy update. Copy and modify on mutation e.g. new Dictionary(old).Add(key, value)
Hastable - Good read speed (no lock required), sameish weight as dictionary but more expensive to mutate and no generics!
ImmutableDictionary - Poorish read speed, no locking required but more allocations require to update than a dictionary.
ImmutableDictionary - Poorish read speed, no locking required but more allocations require to update than a dictionary.
This sort of guidance usually only comes up when implementation tradeoffs are being made but Iβd love to spend more time documenting details like thisβ¦
Loading suggestions...