NativeMemory 0.0.1

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

NativeMemory

Important bits and pieces

  • NativeArray<T>: Access native data

  • NativeArrayPool<T>: Just like ArrayPool, pools native arrays

  • INativeAllocator

    • HGlobalMemAllocator: Allocates memory using Marshal.AllocHGlobal
    • CoTaskMemAllocator: Marshal.AllocCoTaskMem

Sample Code

Using the ArrayPool:

// allocates a new array with 10 bytes
var array = new NativeArray<byte>(10);
array.Dispose();

// Borrow an array of 200 bytes
array = NativeArrayPool<byte>.SharedHGlobal.Rent(200);

// Return the array to the pool.
NativeArrayPool<byte>.SharedHGlobal.Return(array);

// Borrow an array of 200 bytes and return it using the dispose pattern.
using (array = NativeArrayPool<byte>.SharedHGlobal.Rent(200))
{

}

Thanks

Special thanks to the guys from Poltergeist, where i mostly stole this code got my inspiration from.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.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.0.1 250 11/28/2022