C
C#2y ago
DaVinki

❔ What is the difference between string pool and intern pool?

In the Windows Community Toolkit's high performance library, there is a string pool. What makes this different from the intern pool that .NET has? They both store strings to reuse so I'm curious
4 Replies
ero
ero2y ago
just posting here because i want to know too
LPeter1997
LPeter19972y ago
The best is to ask the doc itself https://learn.microsoft.com/en-us/dotnet/communitytoolkit/high-performance/stringpool
It provides a mechanism that is somewhat similar to string interning, with the main differences being that the pool is configurable, can be reset, is implemented with a best-effort policy and doesn't require to pre-instantiate string objects, so it can save the initial allocations as well when working on temporary buffers.
Interning happens in one, central place you don't have power over This pool you can divide up, and have some configuration over it Example: We were writing a grammar tool, where the user typed in a context-free grammar and we provided a bunch of transformations and analysis over the grammar. For the names of terminals and nonterminals, we started using interning for the obvious, it made a lot of logic simpler and cut down on comparisons and memory costs here and there. Some transformations ended up duplicating a lot of these names. Imagine foo suddenly appearing a million times instead of like 20. The problem with that, is that interning does take a bit of time. And all different grammars shared the same interning process, but we didn't need that, since different grammars didn't interact. We sped up the thing by providing each grammar their own pool Essentially... associative container is faster if it has less entries and by that (because it's likely hash-based) less collisions. If you know which pool you want to find your thing, lookup becomes way faster
DaVinki
DaVinkiOP2y ago
I see, that makes sense Thanks
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server