Hertzole.ArrayPoolScope
2.2.1
dotnet add package Hertzole.ArrayPoolScope --version 2.2.1
NuGet\Install-Package Hertzole.ArrayPoolScope -Version 2.2.1
<PackageReference Include="Hertzole.ArrayPoolScope" Version="2.2.1" />
paket add Hertzole.ArrayPoolScope --version 2.2.1
#r "nuget: Hertzole.ArrayPoolScope, 2.2.1"
// Install Hertzole.ArrayPoolScope as a Cake Addin #addin nuget:?package=Hertzole.ArrayPoolScope&version=2.2.1 // Install Hertzole.ArrayPoolScope as a Cake Tool #tool nuget:?package=Hertzole.ArrayPoolScope&version=2.2.1
Array Pool Scope
Array Pool Scope allows you to use ArrayPool in a scope-like manner.
๐ Features
- ๐ Fast and Safe - Use
ArrayPool
in a scope-like manner using readonly structs with no allocations! - โ Fully trimmable and AOT compatible - No reflection or dynamic code is used, making it fully compatible with AOT platforms like NativeAOT and IL2CPP!
- ๐ Wide range of .NET support - Supports .NET Standard 1.1 and up, including .NET Framework 4.6.1, .NET 5+ and even Unity!
- โ 100% test coverage - All code is tested to make sure it works as expected!
- ๐ Almost zero allocations - The library is designed to be as allocation-free as possible!ยน
- ๐ Fully documented - Every public member is documented with XML docs to make it easy to understand how to use the library!
ยน Sort(Comparison<T>)
will allocate a small amount of memory in anything below .NET 5 due to the lack of efficient sorting methods.
๐จ Quick Start
using Hertzole.Buffers;
int length = 10;
// Use a using statement to automatically return the array to the pool.
using (ArrayPoolScope<int> pool = new ArrayPoolScope<int>(length))
{
// For loop
for (int i = 0; i < pool.Length; i++)
{
pool[i] = i;
Console.WriteLine(pool[i]);
}
// Foreach loop
foreach (int item in pool)
{
Console.WriteLine(item);
}
}
// Manully return the array to the pool.
ArrayPoolScope<int> pool = new ArrayPoolScope<int>(length);
pool.Dispose();
// Provide your own pool.
ArrayPool<int> customPool = ArrayPool<int>.Create();
using ArrayPoolScope<int> pool = new ArrayPoolScope<int>(length, customPool);
// Get directly from pool.
using ArrayPoolScope<int> pool = ArrayPool<int>.Shared.RentScope(length);
// As span and memory.
using ArrayPoolScope<int> pool = ArrayPool<int>.Shared.RentScope(length);
Span<int> span = pool.AsSpan();
Memory<int> memory = pool.AsMemory();
// Control how the array is cleared when disposed.
ArrayClearMode clearMode = ArrayClearMode.Auto; // Auto, Always, Never
using ArrayPoolScope<int> pool = new ArrayPoolScope<int>(length, clearMode);
// Get the array directly if needed. (you should avoid this, unless you really need the array)
using ArrayPoolScope<int> pool = ArrayPool<int>.Shared.RentScope(length);
int[] array = UnsafeArrayPool.GetArray(pool);
๐ฆ Installation
You can install the package via NuGet. The package supports .NET Standard 2.0 and up.
dotnet add package Hertzole.ArrayPoolScope
Unity Installation
OpenUPM (Recommended)
The minimum Unity version for Array Pool Scope is 2021.3.
You can install the package through OpenUPM by using the OpenUPM CLI.
openupm add se.hertzole.array-pool-scope
If you don't have the CLI installed, you can follow these steps:
- Open Edit/Project Settings/Package Manager
- Add a new Scoped Registry (or edit the existing OpenUPM entry)
Name:package.openupm.com
URL:https://package.openupm.com
Scope:se.hertzole.array-pool-scope
- Click
Save
(orApply
) - Open Window/Package Manager
- Click
+
- Select
Add package by name...
orAdd package from git URL...
- Paste
se.hertzole.array-pool-scope
into name - Click
Add
Unity Package Manager
You can install the package through the Unity Package Manager.
- Open
Window/Package Manager
- Click the
+
in the top left corner - Select
Add package from git URL...
- Paste
https://github.com/Hertzole/array-pool-scope.git#upm
๐ป Development
Requirements
For standard .NET development, you need the following:
For Unity development, you need the following:
Building
To build the project, you can use the dotnet
CLI.
dotnet build
Testing
To run the tests, you can use the dotnet
CLI.
dotnet test
Unity
The main SDK should be the "single source of truth". This means that all code should be written in the main project and then copied over to the Unity project.
To open the project in Unity, you need to open the Unity
folder as a project.
๐ค Contributing
Contributions, issues and feature requests are welcome!
Please make sure your pull requests are made to the develop
branch and that you have tested your changes. If you're adding a new feature, please also add tests for it.
Your code should follow the C# Coding Conventions. Your commits should follow the Conventional Commits standard.
๐ License
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 is compatible. 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 is compatible. 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 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. 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)
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
-
.NETStandard 2.0
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
-
.NETStandard 2.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.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.