/// <summary> /// Reads a number of elements from a memory location into the provided buffer starting at the specified index. /// </summary> /// <typeparam name="T">The structure type.</typeparam> /// <param name="buffer">The destination buffer.</param> /// <param name="source">The source memory location.</param> /// <param name="index">The start index within <paramref name="buffer"/>.</param> /// <param name="count">The number of elements to read.</param> public static unsafe void ReadArray <T>(T[] buffer, IntPtr source, int index, int count) where T : struct { uint elementSize = (uint)SizeOf <T>(); if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count)); } if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index)); } if (buffer.Length - index < count) { throw new ArgumentException(RS.InvalidOffsetIntoArray); } void *ptr = source.ToPointer(); byte *p = (byte *)FastStructure.GetPtr <T>(ref buffer[0]); #if NETFX UnsafeNativeMethods.CopyMemoryPtr(p + (index * elementSize), ptr, (uint)(elementSize * count)); #else Buffer.MemoryCopy(ptr, p + (index * elementSize), elementSize * count, elementSize * count); #endif }
/// <summary> /// Retrieve a pointer to the passed generic structure type. This is achieved by emitting a <see cref="DynamicMethod"/> to /// retrieve a pointer to the structure. /// </summary> /// <typeparam name="T">The structure type.</typeparam> /// <param name="structure">The structure to search.</param> /// <returns>A pointer to the provided structure in memory.</returns> /// <see cref="FastStructure{T}.GetPtr"/> public static unsafe void *GetPtr <T>(ref T structure) where T : struct { return(FastStructure <T> .GetPtr(ref structure)); }