Collections.Pooled 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Collections.Pooled --version 1.0.1                
NuGet\Install-Package Collections.Pooled -Version 1.0.1                
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="Collections.Pooled" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Collections.Pooled --version 1.0.1                
#r "nuget: Collections.Pooled, 1.0.1"                
#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 Collections.Pooled as a Cake Addin
#addin nuget:?package=Collections.Pooled&version=1.0.1

// Install Collections.Pooled as a Cake Tool
#tool nuget:?package=Collections.Pooled&version=1.0.1                

Collections.Pooled

This library is based on classes from System.Collections.Generic that have been altered to take advantage of the new System.Span<T> and System.Buffers.ArrayPool<T> libraries to minimize memory allocations, improve performance, and/or allow greater interoperablity with modern API's.

Collections.Pooled supports both .NET Standard 2.0 (.NET Framework 4.6.1+) as well as an optimized build for .NET Core 2.2+. An extensive set of unit tests and benchmarks have been ported from corefx.

Benchmarks

Collections

PooledList<T>

PooledList<T> is based on the corefx source code for System.Collections.Generic.List<T>, modified to use ArrayPool for internal array-storage allocation, and to support Span<T>.

There are some API changes worth noting:

  • Find and FindLast have become TryFind and TryFindLast, following the standard .NET "try" pattern.
  • The new PooledList<T>.Span property returns a Span<T> over the portion of the internal array store that is populated. This span can be further sliced, or passed into other methods that can read from or write to a span.
    • Enumerating the Span property can be more than twice as fast as enumerating the list itself, but as we are unable to do the normal "collection modified during enumeration" checks, please use with caution.
    • The list is unable to increment its version-checking flag when setting values via the Span. Therefore, "collection modified during enumeration" checks can be bypassed. Please use with caution.
  • GetRange now returns a Span<T>. For example, foo.GetRange(5, 100) is equivalent to foo.Span.Slice(5, 100).
  • CopyTo now takes a Span<T> and doesn't offer any start-index or count parameters. Use the Span property and slicing instead.
  • AddRange and InsertRange can now accept a ReadOnlySpan<T>.
  • The new AddSpan and InsertSpan methods ensure the internal storage has the capacity to add the requested number of items, and return a Span<T> that can be used to write directly to that section of the internal storage. Caveats about "collection modified during enumeration" checks apply here as well.
  • Delegate types such as Predicate<T> and Converter<T1, T2> have been replaced with standard Func<> equivalents.
  • PooledList implements IDisposable. Disposing the list returns the internal array to the ArrayPool. If you forget to dispose the list, nothing will break, but memory allocations will go up, and so will GC pauses.
Performance

Please review the benchmark links above for complete details. Performance and memory allocations both range from "on par with List<T>" to "far better than List<T>" depending on the operation.

For example, AddRange is a particular strength for PooledList. In the extreme case of using AddRange to add a million integers 5000 times, List<T> allocates 19.5 GB while PooledList<T> allocates 156 KB and gets it done in 13% of the time.

Product 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework 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 tizen40 was computed.  tizen60 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 (22)

Showing the top 5 NuGet packages that depend on Collections.Pooled:

Package Downloads
CosmosStack.Extensions.Collections

CosmosStack collections extension library

Arch

A high performance c# net.7 and net.8 archetype based ECS ( Entity component system ).

TextControlBox.JuliusKirsch

A fast and powerful textbox with syntaxhighlighting and much more

MoonTools.Core.Graph

A GC-friendly graph theory library for .NET Core intended for use with games.

Dispose.Scope

This library is a class library that allows you to easily use scopes to manage instances of objects that implement the `IDisposable` interface. Register the `IDisposable`s that need to be released into the scope, and then automatically release all registered objects at the end of the scope.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Collections.Pooled:

Repository Stars
genaray/Arch
A high-performance C# based Archetype & Chunks Entity Component System (ECS) with optional multithreading.
mirbeta/OpenMir2
Legend of Mir 2 Game server
AnnulusGames/Arch.Unity
Arch ECS integration for Unity.
Version Downloads Last updated
2.0.0-preview.27 309,463 11/28/2019
2.0.0-preview.26 310 11/13/2019
2.0.0-preview.25 300 11/13/2019
2.0.0-preview.24 478 9/24/2019
2.0.0-preview.23 303 9/5/2019
2.0.0-preview.22 308 9/5/2019
2.0.0-preview.21 301 9/5/2019
2.0.0-preview.20 323 8/14/2019
2.0.0-preview.19 337 8/10/2019
2.0.0-preview.18 333 8/8/2019
2.0.0-preview.16 324 6/23/2019
2.0.0-preview.15 307 6/23/2019
2.0.0-preview.14 320 6/23/2019
2.0.0-preview.13 353 5/19/2019
2.0.0-preview.12 350 5/18/2019
2.0.0-preview.11 331 5/18/2019
2.0.0-preview.10 330 5/18/2019
2.0.0-preview.9 341 5/7/2019
2.0.0-preview.8 350 4/19/2019
2.0.0-preview.7 327 4/8/2019
2.0.0-preview.6 338 4/7/2019
2.0.0-preview.5 321 4/7/2019
2.0.0-preview.4 316 4/7/2019
2.0.0-preview.3 329 4/7/2019
2.0.0-preview.2 1,584 4/7/2019
1.0.82 481,303 4/3/2019
1.0.77 13,806 2/12/2019
1.0.68 705 2/9/2019
1.0.61 703 2/6/2019
1.0.54 730 2/6/2019
1.0.47 701 1/31/2019
1.0.38 708 1/28/2019
1.0.21 681 1/24/2019
1.0.6 720 1/24/2019
1.0.5 707 1/24/2019
1.0.4 737 1/23/2019
1.0.3.1 725 1/22/2019
1.0.3 750 1/21/2019
1.0.2 749 1/19/2019
1.0.1 722 12/25/2018
1.0.0 900 12/24/2018