I'm not seeing the point in the need to use DllImport and C? If you're using C# you could just use these functions in C#.
using System.Runtime.InteropServices;
static IntPtr AllocateMem() => Marshal.AllocHGlobal(4096);
static void FreeMem(IntPtr mem) => Marshal.FreeHGlobal(mem);
This would help prevent the need for extra dependencies while providing better optimazation and memory management.