Enhanced C#
Language of your choice: library documentation
Loyc.SymbolPool Class Reference

A collection of Symbols. More...


Source file:
Inheritance diagram for Loyc.SymbolPool:
Loyc.SymbolPool< SymbolE >

Remarks

A collection of Symbols.

There is one global symbol pool (GSymbol.Pool) and you can create an unlimited number of private pools, each with an independent namespace.

Methods of this class are synchronized, so a SymbolPool can be used from multiple threads.

By default, SymbolPool uses weak references to refer to Symbols, so they can be garbage-collected when no longer in use. When creating a private pool you can tell the SymbolPool constructor to use strong references instead, which ensures that none of the symbols disappear, but risks a memory leak if the pool itself is never garbage-collected. Strong references also require less memory and may be slightly faster.

By default, all Symbol are given non-negative IDs. GSymbol.Empty (whose Name is "") has an Id of 0, but in a private pool, "" is not treated differently than any other symbol so a new ID will be allocated for it.