Karma.CoreInvoke 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Karma.CoreInvoke --version 1.1.0                
NuGet\Install-Package Karma.CoreInvoke -Version 1.1.0                
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="Karma.CoreInvoke" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Karma.CoreInvoke --version 1.1.0                
#r "nuget: Karma.CoreInvoke, 1.1.0"                
#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.
// Install Karma.CoreInvoke as a Cake Addin
#addin nuget:?package=Karma.CoreInvoke&version=1.1.0

// Install Karma.CoreInvoke as a Cake Tool
#tool nuget:?package=Karma.CoreInvoke&version=1.1.0                

CoreInvoke is a lightweight, blazing fast replacement for P/Invoke for C# 10+.

It does this by utilizing CALLI instructions through the unmanaged pointer syntax over regular external function bindings.
This also allows for defining functions which do not block the garbage collector.

Example

Using CoreInvoke is almost as easy as using P/Invoke:

internal static class ExampleLib {
    // Define a module name used to refer to the library.
    private const string _ModuleName = "libc";

    // Define a native library which takes care of loading the functions we want to use.
    // Using SystemInfo can help make standardized APIs platform-agnostic with a few extra lines of code.
    private static readonly NativeLibrary _Lib = new(_ModuleName, () => {
        if (SystemInfo.IsWindows) return new[] {"msvcrt.dll", "msvcrt140.dll"};
        return SystemInfo.IsOSX ? new[] {"libSystem.dylib"} : new[] {"libc.so.6", "libc.so"};
    });

    // Load all functions within this class once it's type is being initialized
    static ExampleLib() => _Lib.LoadFunctionsFor(typeof(ExampleLib));

    // Define a callable pointer field which get's populated with an 
    // unmanaged pointer to the malloc function from libc.
    [Import(_ModuleName, "malloc")]
    public static readonly delegate* unmanaged<nuint, void*> Malloc = null!;

    // Do the same thing for the free function.
    [Import(_ModuleName, "free")]
    public static readonly delegate* unmanaged<void*, void> Free = null!;
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Karma.CoreInvoke:

Package Downloads
Karma.CoreGPU

Typesafe, low-level bindings for wgpu_native based on CoreInvoke.

Karma.CoreOBJ

Typesafe, low-level bindings for fast_obj based on CoreInvoke.

Karma.MediaCore

Typesafe, low-level bindings for SDL2 based on CoreInvoke.

Karma.LayoutCore

Typesafe, low-level bindings for Yoga based on CoreInvoke.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.3 1,211 2/24/2022
1.4.2 474 2/23/2022
1.4.1 354 2/22/2022
1.4.0 568 2/22/2022
1.3.1 264 2/21/2022
1.3.0 137 2/21/2022
1.2.1 269 2/18/2022
1.2.0 423 2/18/2022
1.1.1 1,064 2/18/2022
1.1.0 568 12/19/2021
1.0.3 262 12/19/2021
1.0.2 268 12/19/2021
1.0.1 279 12/19/2021
1.0.0 264 12/19/2021