Hertzole.ArrayPoolScope 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Hertzole.ArrayPoolScope --version 2.1.0                
NuGet\Install-Package Hertzole.ArrayPoolScope -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hertzole.ArrayPoolScope" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hertzole.ArrayPoolScope --version 2.1.0                
#r "nuget: Hertzole.ArrayPoolScope, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hertzole.ArrayPoolScope as a Cake Addin
#addin nuget:?package=Hertzole.ArrayPoolScope&version=2.1.0

// Install Hertzole.ArrayPoolScope as a Cake Tool
#tool nuget:?package=Hertzole.ArrayPoolScope&version=2.1.0                

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

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:

  1. Open Edit/Project Settings/Package Manager
  2. 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
  3. Click Save (or Apply)
  4. Open Window/Package Manager
  5. Click +
  6. Select Add package by name... or Add package from git URL...
  7. Paste se.hertzole.array-pool-scope into name
  8. Click Add
Unity Package Manager

You can install the package through the Unity Package Manager.

  1. Open Window/Package Manager
  2. Click the + in the top left corner
  3. Select Add package from git URL...
  4. 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

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.2.1 85 10/28/2024
2.1.0 83 10/25/2024
2.0.1 145 10/18/2024
2.0.0 107 9/24/2024
1.1.0 157 8/11/2024
1.0.0 83 7/23/2024