示例#1
0
        public static Scope <UnmanagedBuffer> Alloc <TStruct>(EHeap mem, TStruct init)
            where TStruct : struct
        {
            var buf = Alloc(mem, typeof(TStruct), 1);

            buf.Value.Init(init);
            return(buf);
        }
示例#2
0
 /// <summary>Copy a managed string into unmanaged memory, converting to UTF8 format if required</summary>
 public static Scope <IntPtr> AllocUTF8String(EHeap mem, string str)
 {
     return(Scope.Create(
                () => mem switch
     {
         EHeap.HGlobal => Marshal.StringToHGlobalAnsi(str),
         EHeap.CoTaskMem => Marshal.StringToCoTaskMemAnsi(str),
         _ => throw new Exception($"Unknown global memory type: {mem}"),
     },
示例#3
0
 public static Scope <UnmanagedBuffer> Alloc(EHeap mem, Type type, int count = 1)
 {
     return(Scope.Create(
                () => new UnmanagedBuffer(mem, type, count),
                buf => buf.Dispose()));
 }
示例#4
0
 public static Scope <UnmanagedBuffer> Alloc <TStruct>(EHeap mem, int count = 1)
     where TStruct : struct
 {
     return(Alloc(mem, typeof(TStruct), count));
 }
示例#5
0
 /// <summary>RAII scope for allocated global memory</summary>
 public static Scope <UnmanagedBuffer> Alloc(EHeap mem, int size_in_bytes)
 {
     return(Alloc(mem, typeof(byte), size_in_bytes));
 }