MemLib 0.6.0-alpha

This is a prerelease version of MemLib.
dotnet add package MemLib --version 0.6.0-alpha
                    
NuGet\Install-Package MemLib -Version 0.6.0-alpha
                    
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="MemLib" Version="0.6.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MemLib" Version="0.6.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="MemLib" />
                    
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 MemLib --version 0.6.0-alpha
                    
#r "nuget: MemLib, 0.6.0-alpha"
                    
#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 MemLib@0.6.0-alpha
                    
#: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=MemLib&version=0.6.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MemLib&version=0.6.0-alpha&prerelease
                    
Install as a Cake Tool

MemLib

This tiny library is an aligned memory allocator for managed and unmanaged memory. Also it can return an allocated memory in the existing buffer.


🚀 Features

  • Can allocate and return alligned memory as Span<T>, Memory<T> or MemoryManager<T>.
  • For methods that directly return Span<T> or Memory<T> - the backed storage is a managed byte array with type of byte[T].
  • For methods that return MemoryManager<T> - the backed storage is either unmanaged byte array with type of byte[T] or managed byte array with type of byte[T] which is pooled by ArrayPool.
  • For perfomance resons methods of MemAlloc.Unsafe class don't zero their backint memory buffers and don't do any arguments validation checks.
  • For sefty resons methodss of MemAlloc.Safe class does do arguments validation checks by cost of addition processor time and for perfomance resons thei don't zero their backing memory buffers.
  • MemAlloc.Unsafe.Zeroed and MemAlloc.Safe.Zeroed members do initialize by zero their buffers but with addition perfomance cost.
  • For already allocated memory buffer can return Span<T>, contained a managed allocated pointer in that buffer (especially for stack allocation).
  • Helper methods in MemAlloc.Address class contain address alignment manipulation functions.

Description

This project uses Semantic Versioning - see more on: https://semver.org/


📦 Installation

Clone the repository and build the project:


Usage

  • int length = 128;
  • int alignment = 16;
  • using MemoryManager<byte> memMgr = MemAlloc.Unsafe<byte>.MemoryUnmanagedAligned(length, alignment);
  • Memory<byte> memory = memMgr.Memory;
  • Span<byte> span = memMgr.GetSpan();

Tests

dotnet test


Licensing

This project is licensed under the MIT License. See the LICENSE file for details.


📬 Contact

If you have any questions, suggestions, or issues, feel free to reach out:

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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
0.6.0-alpha 42 1/27/2026
0.5.0-alpha 136 12/23/2025
0.2.0-alpha 223 12/16/2025

Initial release under MIT License