public static unsafe void WriteArray <T>(IntPtr destination, T[] buffer, int index, int count) where T : struct { uint elementSize = (uint)SizeOf <T>(); if (buffer == null) { throw new ArgumentNullException("buffer"); } if (count < 0) { throw new ArgumentOutOfRangeException("count"); } if (index < 0) { throw new ArgumentOutOfRangeException("index"); } if (buffer.Length - index < count) { throw new ArgumentException("Invalid offset into array specified by index and count"); } void *ptr = destination.ToPointer(); byte *p = (byte *)FastStructure.GetPtr <T>(ref buffer[0]); Buffer.MemoryCopy(p + (index * elementSize), ptr, elementSize * count, elementSize * count); }
internal unsafe T GetResultFast <T>() where T : struct { fixed(byte *functionData = m_context.functionData) { return(FastStructure <T> .PtrToStructure(new IntPtr(functionData))); } }
internal static unsafe void PushFast <T>(ContextType *cxt, T arg) where T : struct { var size = FastStructure <T> .Size; var numArgs = (size / 8); if ((size % 8) != 0) { *(long *)(&cxt->functionData[8 * cxt->numArguments]) = 0; numArgs++; } FastStructure <T> .StructureToPtr(ref arg, new IntPtr(&cxt->functionData[8 * cxt->numArguments])); cxt->numArguments += numArgs; }
internal unsafe void PushFast <T>(T arg) where T : struct { var size = FastStructure <T> .Size; var numArgs = (size / 8); fixed(byte *functionData = m_context.functionData) { if ((size % 8) != 0) { *(long *)(&functionData[8 * m_context.numArguments]) = 0; numArgs++; } FastStructure <T> .StructureToPtr(ref arg, new IntPtr(&functionData[8 * m_context.numArguments])); } m_context.numArguments += numArgs; }
internal static unsafe T GetResultFast <T>(ContextType *cxt) where T : struct { return(FastStructure <T> .PtrToStructure(new IntPtr(&cxt->functionData))); }
public static unsafe void StructureToPtr <T>(ref T structure, IntPtr pointer) where T : struct { FastStructure <T> .StructureToPtr(ref structure, pointer); }
public static unsafe T PtrToStructure <T>(IntPtr pointer) where T : struct { return(FastStructure <T> .PtrToStructure(pointer)); }
public static unsafe void *GetPtr <T>(ref T structure) where T : struct { return(FastStructure <T> .GetPtr(ref structure)); }