Beizsoft.Interning
1.0.0-rc1
dotnet add package Beizsoft.Interning --version 1.0.0-rc1
NuGet\Install-Package Beizsoft.Interning -Version 1.0.0-rc1
<PackageReference Include="Beizsoft.Interning" Version="1.0.0-rc1" />
paket add Beizsoft.Interning --version 1.0.0-rc1
#r "nuget: Beizsoft.Interning, 1.0.0-rc1"
// Install Beizsoft.Interning as a Cake Addin
#addin nuget:?package=Beizsoft.Interning&version=1.0.0-rc1&prerelease
// Install Beizsoft.Interning as a Cake Tool
#tool nuget:?package=Beizsoft.Interning&version=1.0.0-rc1&prerelease
Beizsoft.Interning
A .NET interning/reference sharing library.
What?
Interning is the re-use of references for classes with the same content. There are many cases where interning might be useful, but the simplest use-case is for entirely immutable data classes. While .NET comes with a built-in interning implementation for strings, any other immutable class could be interned.
There are two major benefits to interning:
- Memory usage.
- Comparison performance.
1 should be self-explanatory; if you re-use the same reference for identical classes, you are, of course, going to end up with lower memory usage. 2 might not be quite so obvious: if your class is interned by default, all comparisons can be simple, performant ReferenceEquals
calls. Hashing can be a simple RuntimeHelpers.GetHashCode
call, or hashes can be pre-calculated once, and only once, for all given instances of a class.
How?
There are code examples below in the Usage
section, but for an overview, this library uses the concept of an 'interning key' (a read only struct containing all the data required to build a class) which lives on the stack, and a dictionary-based lookup to ensure only once instance is used for any given reference state.
Classes can be interned-by-default by giving them a private constructor, and a static For
method in the constructor's place, or they can be interned as required by allowing non-interned construction via a public constructor.
Usage
The repository contains simple examples of how to use the library.
Users may choose to change the interning provider for any given interned class/interning key pair, with the default being a concurrent dictionary-based implementation, and the alternatives being a simple unsynchronized dictionary, and an implementation which uses a ReaderWriterLockSlim
to synchronize interning.
To change the static interning provider, users must call the Intern<T1,T2>.Initialize
method with ConcurrentInterner<T1,T2>.Instance
, LockedInterner<T1,T2>.Instance
or UnsynchronizedInterner<T1,T2>.Instance
. Custom implementations can also be enabled via this mechanism.
Should the user attempt to change the static interner after any interning has occurred, an InvalidOperationException
will be thrown.
Because the built-in interning providers are public, and it is perfectly possible for users to implement their own interning providers, users may choose, if they find a use-case, to have 'sharded' interning, where they use different interning providers directly (even if their code is identical) to have separate instances in different contexts.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.1 is compatible. netstandard1.2 is compatible. netstandard1.3 is compatible. netstandard1.4 is compatible. netstandard1.5 is compatible. netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.1
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.2
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.4
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.6
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|