NativeMemoryArray — A library that takes full advantage of the .NET 6 API to handle huge data of over 2GB

NativeMemoryArray<T>

NativeMemoryArray provides only simple Cysharp.Collections.NativeMemoryArray<T> class. It has where T : unmanaged constraint so you can only use struct that not includes reference type.

  • Allocates from native memory, so it does not use the C# heap.
  • There is no limit of 2GB, and infinite length can be allocated as long as memory allows.
  • Can pass directly via IBufferWriter<T> to MessagePackSerializer, System.Text.Json.Utf8JsonWriter, System.IO.Pipelines, etc.
  • Can pass directly via ReadOnlySequence<T> to Utf8JsonWriter, System.IO.Pipelines, etc.
  • Can pass huge data directly via IReadOnlyList<(ReadOnly)Memory<T>> to RandomAccess (Scatter/Gather API).
  • Slice — AsSpan<T>(), AsMemory<T>()
  • IBufferWriter<T> — CrateBufferWriter()
  • foreach — AsSpanSequence, AsMemorySequence, GetEnumerator
  • pointer — ref T this[], GetPinnableReference()
  • ReadOnlySequence<T> — AsReadOnlySequence()
  • IReadOnlyList<Memory<T>> — AsReadOnlyMemoryList()
  • IReadOnlyList<ReadOnlyMemory<T>> — AsMemoryList()

Array.MaxValue

By the way, before .NET 6, the limit for the number of array elements was set differently for byte arrays (arrays of 1-byte structures) and other arrays. For example, quote the documentation for System.Array

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yoshifumi Kawai

Yoshifumi Kawai

a.k.a. neuecc. Creator of UniRx, UniTask, MessagePack for C#, MagicOnion etc. Microsoft MVP for C#. CEO/CTO of Cysharp Inc. Live and work in Tokyo, Japan.