NativeCollections 1.5.0
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Standard 2.1
This package targets .NET Standard 2.1. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NativeCollections --version 1.5.0
NuGet\Install-Package NativeCollections -Version 1.5.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="NativeCollections" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NativeCollections" Version="1.5.0" />
<PackageReference Include="NativeCollections" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NativeCollections --version 1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NativeCollections, 1.5.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.
#:package NativeCollections@1.5.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NativeCollections&version=1.5.0
#tool nuget:?package=NativeCollections&version=1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NativeCollections
Introduction
- It is fully based on unmanaged memory, allowing developers to manipulate memory with lower overhead and more control, while offering a wide range of container types.
- The library provides extensive support for
Span<T>
andunsafe
operations, making it suitable for scenarios with strict performance and memory behavior requirements.
Features
- ✅ GC-Free Allocation: Most container data is allocated using unmanaged memory, without relying on the CLR garbage collector.
- ✅ High Performance: Compact structures, memory alignment, zero boxing, and support for high-performance algorithms.
- ✅ Span Support: Most containers support
Span<T>
/ReadOnlySpan<T>
, enabling in-place modification and zero-copy data passing. - ✅ Thread-Safe Containers: Includes several concurrent container variants suitable for multithreaded environments.
- ✅ Easy Integration: Uses standard C#, making it easy to replace existing containers.
Why?
Most containers in the standard library cannot be used in unmanaged environments, and many lack support for Span<T>
or ReadOnlySpan<T>
.
For example:
List<T>
does not allow fast access viaSpan<T>
orReadOnlySpan<T>
, which limits both performance and development efficiency.- In older versions of .NET,
Dictionary<TKey, TValue>
does not expose direct references to values, requiring operations to be performed on copies instead. This adds unnecessary overhead in performance-critical scenarios. - In many cases, types like
string
are overkill when only aReadOnlySpan<char>
is needed. By usingNativeString
, it’s possible to avoid frequent string allocations and reduce GC pressure significantly.
How to use?
- All containers are value types or wrap unmanaged pointers. Please avoid using them before proper initialization to prevent undefined behavior.
- Most containers require calling
Dispose()
after use to free unmanaged resources properly. - Usage of most containers is very similar to the standard library counterparts, with added convenience methods like converting to
Span<T>
orReadOnlySpan<T>
. - For short-lived containers, you can take advantage of the
using
statement to automatically callDispose()
. - For
StackallocCollection
series, you can use thestackalloc
syntax. Alternatively, you can provide any fixed buffer from outside, such as unmanaged memory or fixed managed memory. - For
NativeCollection
series, they act as wrappers around theUnsafeCollection
series and additionally store a handle pointer for managing the underlying resource. - For
UnsafeCollection
series, they do not store a handle pointer themselves and are implemented directly as structs, providing a more lightweight but less managed usage. - You can use
NativeMemoryAllocator.Custom
to override:public static void* Alloc(uint byteCount)
public static void* AllocZeroed(uint byteCount)
public static void Free(void* ptr)
- You can use
NativeHashCode.Custom
to override:public static int GetHashCode(ReadOnlySpan<byte> buffer)
.
- You can use
NativeString.Custom
to override:public static int GetHashCode(ReadOnlySpan<char> buffer)
.
Project status
This project is actively under development. Welcome your suggestions and feedback.
License
This project is licensed under the MIT License.
Some implemented types
BitArray
ConcurrentDictionary<TKey, TValue>
ConcurrentHashSet<T>
ConcurrentQueue<T>
ConcurrentStack<T>
Deque<T>
Dictionary<TKey, TValue>
HashSet<T>
List<T>
MemoryStream
OrderedDictionary<TKey, TValue>
OrderedHashSet<T>
PriorityQueue<TKey, TValue>
Queue<T>
SortedDictionary<TKey, TValue>
SortedList<TKey, TValue>
SortedSet<T>
SparseSet<T>
Stack<T>
String
StringBuilder<T>
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. net9.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.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.
Version | Downloads | Last Updated |
---|---|---|
1.5.3 | 132 | 7/13/2025 |
1.5.2 | 196 | 6/13/2025 |
1.5.1 | 80 | 5/24/2025 |
1.5.0 | 150 | 5/21/2025 |
1.4.9 | 149 | 5/21/2025 |
1.4.8 | 146 | 5/20/2025 |
1.4.7 | 228 | 5/15/2025 |
1.4.6 | 225 | 5/14/2025 |
1.4.5 | 221 | 5/14/2025 |
1.4.4 | 226 | 5/13/2025 |
1.4.3 | 135 | 5/11/2025 |
1.4.2 | 124 | 5/9/2025 |
1.4.1 | 141 | 5/7/2025 |
1.4.0 | 144 | 4/30/2025 |
1.3.9 | 148 | 4/29/2025 |
1.3.8 | 156 | 4/29/2025 |
1.3.7 | 161 | 4/28/2025 |
1.3.6 | 157 | 4/28/2025 |
1.3.5 | 173 | 4/27/2025 |
1.3.4 | 169 | 4/22/2025 |
1.3.3 | 160 | 4/21/2025 |
1.3.2 | 156 | 4/21/2025 |
1.3.1 | 138 | 4/18/2025 |
1.3.0 | 199 | 4/17/2025 |
1.2.9 | 192 | 4/17/2025 |
1.2.8 | 204 | 4/15/2025 |
1.2.7 | 205 | 4/14/2025 |
1.2.6 | 195 | 4/14/2025 |
1.2.5 | 185 | 4/13/2025 |
1.2.4 | 158 | 4/12/2025 |
1.2.3 | 99 | 4/12/2025 |
1.2.2 | 116 | 4/11/2025 |
1.2.1 | 175 | 4/8/2025 |
1.2.0 | 166 | 4/8/2025 |
1.1.9 | 173 | 4/8/2025 |
1.1.8 | 171 | 4/8/2025 |
1.1.7 | 163 | 4/7/2025 |
1.1.6 | 114 | 4/4/2025 |
1.1.5 | 100 | 4/4/2025 |
1.1.4 | 113 | 4/4/2025 |
1.1.3 | 152 | 4/4/2025 |
1.1.2 | 162 | 4/3/2025 |
1.1.1 | 166 | 4/3/2025 |
1.1.0 | 170 | 4/1/2025 |
1.0.9 | 171 | 3/31/2025 |
1.0.8 | 157 | 3/31/2025 |
1.0.7 | 144 | 3/27/2025 |
1.0.6 | 147 | 3/26/2025 |
1.0.5 | 475 | 3/26/2025 |
1.0.4 | 473 | 3/26/2025 |
1.0.3 | 346 | 3/24/2025 |
1.0.2 | 154 | 3/20/2025 |
1.0.1 | 158 | 3/19/2025 |
1.0.0 | 148 | 3/18/2025 |