CodeJunkie.ReferencePool
1.0.0
dotnet add package CodeJunkie.ReferencePool --version 1.0.0
NuGet\Install-Package CodeJunkie.ReferencePool -Version 1.0.0
<PackageReference Include="CodeJunkie.ReferencePool" Version="1.0.0" />
<PackageVersion Include="CodeJunkie.ReferencePool" Version="1.0.0" />
<PackageReference Include="CodeJunkie.ReferencePool" />
paket add CodeJunkie.ReferencePool --version 1.0.0
#r "nuget: CodeJunkie.ReferencePool, 1.0.0"
#:package CodeJunkie.ReferencePool@1.0.0
#addin nuget:?package=CodeJunkie.ReferencePool&version=1.0.0
#tool nuget:?package=CodeJunkie.ReferencePool&version=1.0.0
ReferencePool
The ReferencePool class provides a mechanism for managing object pooling to reduce memory allocation and improve performance. It allows acquiring, releasing, adding, and removing references of specific types.
Installation
Install the latest version of the [CodeJunkie.ReferencePool] package from nuget:
dotnet add package CodeJunkie.ReferencePool
Features
- Object Pooling: Efficiently reuse objects to minimize memory allocation overhead.
- Type-Specific Pools: Manage pools for different types of objects.
- Thread-Safe Operations: Ensures safe access to the pool in multi-threaded environments.
- Statistics Tracking: Provides detailed information about the pool's usage, including counts for acquired, released, added, and removed references.
Key Components
ReferencePool
A static class that serves as the entry point for managing reference pools.
- Acquire: Retrieve an object from the pool.
- Release: Return an object to the pool after use.
- Add: Preload objects into the pool.
- Remove: Remove objects from the pool.
- ClearAll: Clear all reference pools.
ReferenceCollection
An internal class that manages a specific type of reference.
- Tracks usage statistics such as:
- Unused references
- References in use
- Total acquired, released, added, and removed references
ReferencePoolInformation
A struct that provides detailed information about a specific reference pool.
- Includes properties for:
- Reference type
- Counts for unused, in-use, acquired, released, added, and removed references
Usage
Acquiring and Releasing References
// Acquire a reference of type MyReference
var reference = ReferencePool.Acquire<MyReference>();
// Use the reference
reference.DoSomething();
// Release the reference back to the pool
ReferencePool.Release(reference);
ReferencePool
The ReferencePool class provides a mechanism for managing object pooling to reduce memory allocation and improve performance. It allows acquiring, releasing, adding, and removing references of specific types.
Features
- Efficiently manage object pooling to minimize memory allocation overhead.
- Support for acquiring and releasing references.
- Ability to add and remove references dynamically.
- Strict type checking for reference management.
- Detailed statistics for reference pool usage.
Namespace
CodeJunkie.ReferencePool
Key Classes and Interfaces
ReferencePool: The main static class for managing reference pools.IReference: Interface that all pooled objects must implement.ReferencePoolInformation: Struct that provides detailed information about the state of a reference pool.
How to Use
1. Implement the IReference Interface
All objects that will be managed by the ReferencePool must implement the IReference interface. This interface requires a Clear method to reset the object's state.
public class MyReference : IReference {
public int Value { get; set; }
public void Clear() {
Value = 0;
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- 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 |
|---|---|---|
| 1.0.0 | 163 | 5/18/2025 |