public static unsafe T Alloc <T1>(byte *buffer, T1 value)
        {
            T returnObject = StackAlloc <T> .AllocInternal((IntPtr *)buffer);

            Constructor <T1> .Invoke(returnObject, value);

            return(returnObject);
        }
        public static unsafe T Alloc(byte *buffer)
        {
            T returnObject = StackAlloc <T> .AllocInternal((IntPtr *)buffer);

            Constructor.Invoke(returnObject);

            return(returnObject);
        }
예제 #3
0
        internal static unsafe T AllocInternal(IntPtr *buffer)
        {
            //Zero the memory to be sure
            StackAlloc <T> .ZeroMemory(buffer + 2);

            Unsafe.AsRef <IntPtr>(buffer)     = IntPtr.Zero;                        //Object Header
            Unsafe.AsRef <IntPtr>(buffer + 1) = StackAlloc <T> .MethodTablePointer; //Method Table Pointer

            IntPtr dataPointer = (IntPtr)Unsafe.AsPointer(ref Unsafe.AsRef <IntPtr>(buffer + 1));

            return(Unsafe.As <IntPtr, T>(ref dataPointer)); //Pointer to the method table pointer
        }
 public static unsafe T Alloc <T1>(Span <byte> buffer, T1 value) => StackAlloc <T> .Alloc(buffer.AsPointer(), value);
 public static unsafe T Alloc(Span <byte> buffer) => StackAlloc <T> .Alloc(buffer.AsPointer());