Skip to content

Instantly share code, notes, and snippets.

@sebas77
sebas77 / BurstHelper.cs
Last active January 25, 2024 23:27
Code to compile c# actions with Burst and use them outside the job system. Attention: it's a hack, use just for experiments only
#if UNITY_BURST_FEATURE_FUNCPTR
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using Unity.Burst;
namespace BurstHelper
@breezhang
breezhang / GetDelegateForFunctionPointer.cs
Created October 6, 2013 09:24
Marshal --> ( Marshal.GetFunctionPointerForDelegate GetDelegateForFunctionPointer)
public static partial class Util
{
const string kDelegateInvokeMethodName = "Invoke";
// http://www.codeproject.com/Tips/441743/A-look-at-marshalling-delegates-in-NET
public static T GetDelegateForFunctionPointer<T>(IntPtr ptr, System.Runtime.InteropServices.CallingConvention call_conv)
where T : class
{
Contract.Requires<ArgumentException>(typeof(T).IsSubclassOf(typeof(Delegate)));
Contract.Requires<ArgumentNullException>(ptr != IntPtr.Zero);
Contract.Requires<ArgumentException>(call_conv != System.Runtime.InteropServices.CallingConvention.ThisCall,