Collections.Pooled
1.0.3
See the version list below for details.
dotnet add package Collections.Pooled --version 1.0.3
NuGet\Install-Package Collections.Pooled -Version 1.0.3
<PackageReference Include="Collections.Pooled" Version="1.0.3" />
paket add Collections.Pooled --version 1.0.3
#r "nuget: Collections.Pooled, 1.0.3"
// Install Collections.Pooled as a Cake Addin #addin nuget:?package=Collections.Pooled&version=1.0.3 // Install Collections.Pooled as a Cake Tool #tool nuget:?package=Collections.Pooled&version=1.0.3
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.1+. An extensive set of unit tests and benchmarks have been ported from corefx.
Installation
Available on NuGet:
Install-Package Collections.Pooled
dotnet add package Collections.Pooled
paket add Collections.Pooled
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
andFindLast
have becomeTryFind
andTryFindLast
, following the standard .NET "try" pattern.- The new
PooledList<T>.Span
property returns aSpan<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 aSpan<T>
. For example,foo.GetRange(5, 100)
is equivalent tofoo.Span.Slice(5, 100)
.CopyTo
now takes aSpan<T>
and doesn't offer any start-index or count parameters. Use theSpan
property and slicing instead.AddRange
andInsertRange
can now accept aReadOnlySpan<T>
.- The new
AddSpan
andInsertSpan
methods ensure the internal storage has the capacity to add the requested number of items, and return aSpan<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>
andConverter<T1, T2>
have been replaced with standardFunc<>
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 and GC pauses will be closer to those
of
List<T>
(you will still benefit from pooling of intermediate arrays as the PooledList is resized). - A selection of
ToPooledList()
extension methods are provided.
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.
PooledDictionary<TKey, TValue>
PooledDictionary<TKey, TValue>
is based on the corefx source code for System.Collections.Generic.Dictionary<TKey, TValue>
,
modified to use ArrayPool for internal storage allocation, and to support Span<T>
.
There are some API changes worth noting:
- New methods include:
AddRange
,GetOrAdd
,AddOrUpdate
- Both constructors and AddRange can take a sequence of
KeyValuePair<TKey, TValue>
objects, or a sequence ofValueTuple<TKey, TValue>
objects. - Significantly reduced memory allocations when adding many items.
- PooledDictionary implements IDisposable. Disposing the dictionary returns the internal arrays to the ArrayPool.
If you forget to dispose the dictionary, nothing will break, but memory allocations and GC pauses will be closer to those
of
Dictionary<TKey, TValue>
(you will still benefit from pooling of intermediate arrays as the PooledDictionary is resized). - A selection of
ToPooledDictionary()
extension methods are provided.
PooledStack<T>
PooledStack<T>
is based on the corefx source code for System.Generic.Collections.Stack<T>
,
modified to use ArrayPool for internal storage allocation.
- Other than the ability to pass Spans into the constructor, there are no API changes compared to the original Stack.
- Significantly reduced memory allocations when pushing many items.
- PooledStack implements IDisposable. Disposing the stack returns the internal arrays to the ArrayPool.
If you forget to dispose the stack, nothing will break, but memory allocations and GC pauses will be closer to those
of
Stack<T>
(you will still benefit from pooling of intermediate arrays as the PooledStack is resized). - A selection of
ToPooledStack()
extension methods are provided.
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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 is compatible. netcoreapp2.2 was computed. 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. |
-
.NETCoreApp 2.1
- No dependencies.
-
.NETStandard 2.0
- System.Buffers (>= 4.5.0)
- System.Memory (>= 4.5.2)
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 | 314,502 | 11/28/2019 |
2.0.0-preview.26 | 313 | 11/13/2019 |
2.0.0-preview.25 | 303 | 11/13/2019 |
2.0.0-preview.24 | 481 | 9/24/2019 |
2.0.0-preview.23 | 306 | 9/5/2019 |
2.0.0-preview.22 | 311 | 9/5/2019 |
2.0.0-preview.21 | 304 | 9/5/2019 |
2.0.0-preview.20 | 326 | 8/14/2019 |
2.0.0-preview.19 | 340 | 8/10/2019 |
2.0.0-preview.18 | 336 | 8/8/2019 |
2.0.0-preview.16 | 327 | 6/23/2019 |
2.0.0-preview.15 | 310 | 6/23/2019 |
2.0.0-preview.14 | 323 | 6/23/2019 |
2.0.0-preview.13 | 356 | 5/19/2019 |
2.0.0-preview.12 | 353 | 5/18/2019 |
2.0.0-preview.11 | 334 | 5/18/2019 |
2.0.0-preview.10 | 333 | 5/18/2019 |
2.0.0-preview.9 | 344 | 5/7/2019 |
2.0.0-preview.8 | 353 | 4/19/2019 |
2.0.0-preview.7 | 330 | 4/8/2019 |
2.0.0-preview.6 | 341 | 4/7/2019 |
2.0.0-preview.5 | 324 | 4/7/2019 |
2.0.0-preview.4 | 319 | 4/7/2019 |
2.0.0-preview.3 | 332 | 4/7/2019 |
2.0.0-preview.2 | 1,615 | 4/7/2019 |
1.0.82 | 488,927 | 4/3/2019 |
1.0.77 | 13,810 | 2/12/2019 |
1.0.68 | 708 | 2/9/2019 |
1.0.61 | 706 | 2/6/2019 |
1.0.54 | 733 | 2/6/2019 |
1.0.47 | 704 | 1/31/2019 |
1.0.38 | 711 | 1/28/2019 |
1.0.21 | 684 | 1/24/2019 |
1.0.6 | 723 | 1/24/2019 |
1.0.5 | 710 | 1/24/2019 |
1.0.4 | 741 | 1/23/2019 |
1.0.3.1 | 728 | 1/22/2019 |
1.0.3 | 753 | 1/21/2019 |
1.0.2 | 752 | 1/19/2019 |
1.0.1 | 725 | 12/25/2018 |
1.0.0 | 906 | 12/24/2018 |
Adding PooledStack class.