CryptoHives.Foundation.Memory
0.7.75
dotnet add package CryptoHives.Foundation.Memory --version 0.7.75
NuGet\Install-Package CryptoHives.Foundation.Memory -Version 0.7.75
<PackageReference Include="CryptoHives.Foundation.Memory" Version="0.7.75" />
<PackageVersion Include="CryptoHives.Foundation.Memory" Version="0.7.75" />
<PackageReference Include="CryptoHives.Foundation.Memory" />
paket add CryptoHives.Foundation.Memory --version 0.7.75
#r "nuget: CryptoHives.Foundation.Memory, 0.7.75"
#:package CryptoHives.Foundation.Memory@0.7.75
#addin nuget:?package=CryptoHives.Foundation.Memory&version=0.7.75
#tool nuget:?package=CryptoHives.Foundation.Memory&version=0.7.75
π‘οΈ CryptoHives Open Source Initiative π
An open, community-driven collection of cryptography and performance libraries for the .NET ecosystem, maintained by The Keepers of the CryptoHives.
π§ CryptoHives.Foundation.Memory
Pooled buffer management for .NET, built to keep allocations and GC pressure out of high-throughput transformation pipelines and crypto workloads.
π₯ Installation
dotnet add package CryptoHives.Foundation.Memory
β¨ Key Features
- Pooled memory streams
- Zero-copy handoff β expose written data as a
ReadOnlySequence<byte>without copying anything IBufferWriter<T>support βArrayPoolBufferWriter<T>works directly withUtf8JsonWriter,PipeWriter, or any otherIBufferWriterconsumer- Read-only sequence streaming β wrap an existing
ReadOnlySequence<byte>as aStreamwithout copying - Lifetime-bound payloads β
SequenceLease<T>carries aReadOnlySequence<T>together with the producer that owns it, so data can leave the scope that built it without a copy and without an allocation - Poolable buffer writers β the writer itself is recycled, not just its buffers;
ArrayPoolBufferWriterProvider<T>keeps many settings profiles on a single shared pool - Opt-in zeroing β
clearArraywipes a buffer on its way back to the pool, for callers holding key material - RAII ownership β
ObjectOwner<T>returns pooled objects automatically on dispose - Segment ownership primitives β
ISegmentOwner<T>unifies three strategies:PooledSegment<T>rents fromArrayPool<T>,AllocatedSegment<T>wraps GC-managed arrays, andEmptySegment<T>is a zero-allocation null-object sentinel
π‘ Quick Examples
Pooled Memory Stream
using CryptoHives.Foundation.Memory.Buffers;
// Write data in chunks, then hand off as ReadOnlySequence β zero copy
using var stream = new ArrayPoolMemoryStream();
await stream.WriteAsync(headerBytes, ct).ConfigureAwait(false);
await stream.WriteAsync(payloadBytes, ct).ConfigureAwait(false);
// No copy β memory stays in the pool segments
ReadOnlySequence<byte> sequence = stream.GetReadOnlySequence();
await SendAsync(sequence, ct).ConfigureAwait(false);
// Pooled buffers are returned when the stream is disposed
Buffer Writer (e.g. with Utf8JsonWriter)
using CryptoHives.Foundation.Memory.Buffers;
using System.Text.Json;
using var writer = new ArrayPoolBufferWriter<byte>();
using var json = new Utf8JsonWriter(writer);
json.WriteStartObject();
json.WriteString("key", "value");
json.WriteEndObject();
json.Flush();
ReadOnlySequence<byte> result = writer.GetReadOnlySequence();
await socket.SendAsync(result.First, WebSocketMessageType.Text, true, ct).ConfigureAwait(false);
// Pooled chunks returned on dispose
Handing a Payload Past the Scope That Built It
static SequenceLease<byte> BuildPayload()
{
var writer = ObjectPools.RentBufferWriter<byte>(); // deliberately not `using`
Serialize(writer);
return writer.LeaseSequence(); // the writer rides along
}
using SequenceLease<byte> payload = BuildPayload();
var reader = new Utf8JsonReader(payload.Sequence); // read in place, no copy
// disposing the lease returns the writer to its pool, and its buffers to ArrayPool
Read-Only Sequence as Stream
using CryptoHives.Foundation.Memory.Buffers;
// Consume an existing ReadOnlySequence<byte> through a Stream interface β zero copy
ReadOnlySequence<byte> data = pipeline.GetData();
using var stream = new ReadOnlySequenceMemoryStream(data);
await DeserializeFromStreamAsync(stream, ct).ConfigureAwait(false);
RAII Object Ownership
using CryptoHives.Foundation.Memory.Pools;
using Microsoft.Extensions.ObjectPool;
// Any Microsoft.Extensions.ObjectPool pool works; PoolFactory builds one from a factory
// and a reset delegate, including for types this package does not reference
ObjectPool<MyExpensiveObject> pool = PoolFactory.CreatePool(
create: () => new MyExpensiveObject(),
reset: obj => { obj.Clear(); return true; });
using var owner = new ObjectOwner<MyExpensiveObject>(pool);
MyExpensiveObject obj = owner.PooledObject;
// Use obj...
// Automatically returned to the pool when owner is disposed β even on exception
Segment Ownership
using CryptoHives.Foundation.Memory.Buffers;
// Pool-backed: rented from ArrayPool<byte>, returned on dispose
using ISegmentOwner<byte> pooled = PooledSegment<byte>.Rent(256);
Span<byte> span = pooled.Segment.AsSpan();
FillData(span);
// Slice the view without copying
if (pooled.TrySetSegment(offset: 16, length: 64))
{
Span<byte> payload = pooled.Segment.AsSpan();
SendPayload(payload);
}
// GC-managed: wrap an existing array, no pool lifecycle needed
byte[] buffer = new byte[256];
using ISegmentOwner<byte> alloc = AllocatedSegment<byte>.Create(buffer);
// Empty sentinel: null-object that avoids null checks
ISegmentOwner<byte> none = EmptySegment<byte>.Instance;
π Documentation
| Resource | Link |
|---|---|
| Full package documentation | cryptohives.github.io/Foundation/packages/memory |
| API reference | cryptohives.github.io/β¦/api/β¦Memory.Buffers |
| Source repository | github.com/CryptoHives/Foundation |
π¨ Security Policy
If you discover a vulnerability, please don't open a public issue β report it privately through GitHub's private vulnerability reporting. The CryptoHives Security Page has the details.
βοΈ License
MIT OR Apache-2.0 β Β© 2026 The Keepers of the CryptoHives
See Choosing a license for how to record which one you use.
| 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 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 was computed. 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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. 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. |
-
.NETFramework 4.6.2
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.Bcl.Memory (>= 10.0.15)
- Microsoft.Extensions.ObjectPool (>= 10.0.15)
- System.Memory (>= 4.6.3)
-
.NETStandard 2.0
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.Bcl.Memory (>= 10.0.15)
- Microsoft.Extensions.ObjectPool (>= 10.0.15)
- System.Memory (>= 4.6.3)
-
.NETStandard 2.1
- Microsoft.Bcl.Memory (>= 10.0.15)
- Microsoft.Extensions.ObjectPool (>= 10.0.15)
-
net10.0
- Microsoft.Extensions.ObjectPool (>= 10.0.15)
-
net8.0
- Microsoft.Extensions.ObjectPool (>= 10.0.15)
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 |
|---|---|---|
| 0.7.75 | 99 | 11/14/2026 |
| 0.7.59 | 191 | 10/30/2026 |
| 0.7.37 | 306 | 9/30/2026 |
| 0.6.101 | 328 | 9/1/2026 |
| 0.6.79 | 282 | 8/12/2026 |
| 0.6.51 | 267 | 8/1/2026 |
| 0.6.21 | 304 | 7/4/2026 |
| 0.5.34-preview | 662 | 6/2/2026 |
| 0.5.21-preview | 192 | 5/2/2026 |
| 0.5.13-preview | 142 | 4/2/2026 |
| 0.4.21-preview | 139 | 3/1/2026 |
| 0.4.11-preview | 156 | 2/14/2026 |
| 0.3.19-preview | 150 | 1/26/2026 |
| 0.2.43-preview | 148 | 1/9/2026 |
| 0.2.33-preview | 496 | 12/9/2025 |
| 0.2.30-preview | 393 | 12/8/2025 |
| 0.2.28-preview | 354 | 12/7/2025 |
| 0.2.26-preview | 271 | 12/6/2025 |
| 0.2.22-preview | 630 | 12/1/2025 |
| 0.2.17-preview | 242 | 11/23/2025 |