Hezium.Memory 为 .NET 10+ 提供了使用 nint 索引的 BigArray、BigMemory、BigSpan 等类型,支持超过 Array.MaxLength 的数组和跨度,并保持熟悉的 API 模式。

Stars

37

7 天增长

暂无数据

Fork 数

2

开放 Issue

1

开源协议

MIT

最近更新

2026-07-28

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

该库通过支持超出 2^31-1 元素限制的托管数组,同时保留 Array/Memory/Span 编程模式,填补了 .NET 内存模型的空白;支持垃圾回收,基准测试显示其性能与交错数组相当或更优。

适合谁使用

  • 处理极大型数据集的 .NET 开发者
  • 高性能计算和模拟工程师
  • 需要大型连续缓冲区的游戏开发者
  • 列式存储和数据管道的实现者

典型使用场景

  • 存储和处理超过 System.Array.MaxLength 的列式数据
  • 大型模拟的预计算查找表
  • 需要托管内存且支持 GC 的本机互操作缓冲区
  • 基于文件的大型一维集合处理管道

项目优势

  • 熟悉的 API 接口,镜像 Array、Span<T>、Memory<T>,但使用 nint 长度和索引
  • 支持垃圾回收的托管分配,可选固定存储
  • 基准测试显示在分配和访问性能上与交错数组相当或更优
  • 提供与 System.Span<T> 一致的搜索、排序、复制、修剪和拆分操作

使用前须知

  • 需要 .NET 10 或更高版本
  • 拒绝大小超过 65535 字节的值类型
  • 大型数组使用分块存储,某些操作可能带来轻微开销

README 快速开始

Hezium.Memory

BigArray, BigMemory, BigReadOnlyMemory, BigSpan, and BigReadOnlySpan for .NET code that wants the Array/Memory/Span programming model with nint lengths and indexes.

The standard T[] and Span APIs are excellent until the array you want to model is larger than the largest single managed array. Hezium.Memory keeps the surface area familiar: allocate an owner, take a span-like view, slice it, search it, copy it, sort it, and pass references around without inventing a second indexing style.

dotnet add package Hezium.Memory
using Hezium.Memory;

nint length = 10_000_000_000;
BigArray buffer = new(length);

buffer[0] = 1;
buffer[5_000_000_000] = 2;
buffer[length - 1] = 3;

BigSpan window = buffer.AsBigSpan(5_000_000_000, 1024);

window[0] = 42;
Console.WriteLine(buffer[5_000_000_000]); // 42

BigArray allocates on managed memory with GC support, so you can use it with reference types and it will be collected when no longer being used.

For explicit GC-style allocation, use GC.AllocateBigArray() or GC.AllocateUninitializedBigArray(). Both APIs accept the same pinned option as the built-in GC array allocation helpers.

BigArray zeroed = GC.AllocateBigArray(length);
BigArray scratch = GC.AllocateUninitializedBigArray(length);
BigArray pinned = GC.AllocateBigArray(length, pinned: true);

For more details about how this library was built, see the Introduction.

Why

Some workloads are naturally one-dimensional and very large: columnar data, precomputed lookup tables, native interop buffers, generated datasets, simulation state, and file-backed processing pipelines. The important part is not only "can I allocate a lot of elements", but "can I keep using the same mental model when I do?"

Hezium.Memory is built around that goal:

  • BigArray is the owning storage type.
  • BigMemory is the mutable storable view.
  • BigReadOnlyMemory is the read-only storable view.
  • BigSpan is the mutable stack-only view.
  • BigReadOnlySpan is the read-only stack-only view.
  • Lengths, indexes, and offsets are nint.
  • APIs intentionally resemble Array, Memory, ReadOnlyMemory, Span, ReadOnlySpan, and MemoryMarshal.

BigArray

BigArray is a one-d

项目描述

A one-dimensional, zero-based BigArray, BigSpan and BigReadOnlySpan types and helpers for arrays that exceed the standard .NET array limits.

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

loyal-studio
loyal-studio GitHub avatar

Honami-Animation-System

Honami is a visual, UI-first animation system for Unity 6 that replaces Mecanim with timeline editors, node graphs, and a zero-allocation runtime, letting animators author animations with almost no code.

C#
239
aakk007
aakk007 GitHub avatar

RogueCleaner

A Windows tool that detects and removes malicious leftovers from right-click menus, startup items, services, scheduled tasks, browser extensions, and file associations.

C#
212
ThioJoe
ThioJoe GitHub avatar

Thio-Background-App-Notifier

A lightweight Windows tool that notifies you about new auto-starting background services and scheduled tasks that Windows normally doesn't alert you about.

C#
147