CryptoHives.Foundation.Memory 0.5.34-preview

This is a prerelease version of CryptoHives.Foundation.Memory.
There is a newer version of this package available.
See the version list below for details.
dotnet add package CryptoHives.Foundation.Memory --version 0.5.34-preview
                    
NuGet\Install-Package CryptoHives.Foundation.Memory -Version 0.5.34-preview
                    
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="CryptoHives.Foundation.Memory" Version="0.5.34-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CryptoHives.Foundation.Memory" Version="0.5.34-preview" />
                    
Directory.Packages.props
<PackageReference Include="CryptoHives.Foundation.Memory" />
                    
Project file
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 CryptoHives.Foundation.Memory --version 0.5.34-preview
                    
#r "nuget: CryptoHives.Foundation.Memory, 0.5.34-preview"
                    
#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 CryptoHives.Foundation.Memory@0.5.34-preview
                    
#: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=CryptoHives.Foundation.Memory&version=0.5.34-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CryptoHives.Foundation.Memory&version=0.5.34-preview&prerelease
                    
Install as a Cake Tool

🛡️ CryptoHives Open Source Initiative 🐝

An open, community-driven cryptography and performance library collection for the .NET ecosystem, developed and maintained by The Keepers of the CryptoHives.


CryptoHives.Foundation.Memory

NuGet Tests

Pooled buffer management utilities for .NET — designed to minimize allocations and reduce GC pressure in high-throughput transformation pipelines and cryptographic workloads.


📦 Installation

dotnet add package CryptoHives.Foundation.Memory

✨ Key Features

  • Pooled memory streamsMemoryStream replacement backed by ArrayPool<byte>.Shared; no resize-copy, no LOH pressure
  • Zero-copy handoff — expose written data as ReadOnlySequence<byte> without any copying
  • IBufferWriter<T> supportArrayPoolBufferWriter<T> works directly with Utf8JsonWriter, PipeWriter, and any IBufferWriter consumer
  • Read-only sequence streaming — wrap an existing ReadOnlySequence<byte> as a Stream without copying
  • RAII ownershipObjectOwner<T> safely returns pooled objects when disposed

🚀 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 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

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;

var pool = ObjectPools.Create<MyExpensiveObject>();

using var owner = new ObjectOwner<MyExpensiveObject>(pool);
MyExpensiveObject obj = owner.Object;

// Use obj...

// Automatically returned to pool when owner is disposed — even on exception

📚 Documentation

Resource Link
Full package documentation cryptohives.github.io/Foundation/packages/memory
API reference cryptohives.github.io/Foundation/api
Source repository github.com/CryptoHives/Foundation

🔐 Security Policy

If you discover a vulnerability, please do not open a public issue. Follow the guidelines on the CryptoHives Security Page.


⚖️ License

MIT — © 2026 The Keepers of the CryptoHives

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.6.51 144 8/1/2026
0.6.21 274 7/4/2026
0.5.34-preview 626 6/2/2026
0.5.21-preview 161 5/2/2026
0.5.13-preview 118 4/2/2026
0.4.21-preview 117 3/1/2026
0.4.11-preview 130 2/14/2026
0.3.19-preview 128 1/26/2026
0.2.43-preview 132 1/9/2026
0.2.33-preview 478 12/9/2025
0.2.30-preview 372 12/8/2025
0.2.28-preview 338 12/7/2025
0.2.26-preview 253 12/6/2025
0.2.22-preview 608 12/1/2025
0.2.17-preview 227 11/23/2025
0.2.13-preview 435 11/20/2025
0.2.11-preview 1,038 11/19/2025