/* Implementation */ /// <summary> /// Reads a generic type array from a specified memory address. /// </summary> /// <typeparam name="T">An individual struct type of a class with an explicit StructLayout.LayoutKind attribute.</typeparam> /// <param name="memoryAddress">The memory address to read from.</param> /// <param name="value">Local variable to receive the read in struct array.</param> /// <param name="arrayLength">The number of items to read from memory.</param> /// <param name="marshal">Set to true to marshal the element.</param> public static void FromPtr <T>(IntPtr memoryAddress, out T[] value, int arrayLength, bool marshal = false) { int structSize = Struct.GetSize <T>(marshal); value = new T[arrayLength]; for (int x = 0; x < arrayLength; x++) { IntPtr address = memoryAddress + (structSize * x); Struct.FromPtr(address, out T result, marshal); value[x] = result; } }
/* Implementation */ /// <summary> /// Reads a generic type array from a specified memory address. /// </summary> /// <typeparam name="T">An individual struct type of a class with an explicit StructLayout.LayoutKind attribute.</typeparam> /// <param name="memoryAddress">The memory address to read from.</param> /// <param name="value">Local variable to receive the read in struct array.</param> /// <param name="arrayLength">The number of items to read from memory.</param> /// <param name="marshal">Set to true to marshal the element.</param> public static void FromPtr <T>(IntPtr memoryAddress, out T[] value, int arrayLength, bool marshal = false) { int structSize = Struct.GetSize <T>(marshal); #if NET5_0_OR_GREATER value = GC.AllocateUninitializedArray <T>(arrayLength, false); #else value = new T[arrayLength]; #endif for (int x = 0; x < arrayLength; x++) { IntPtr address = memoryAddress + (structSize * x); Struct.FromPtr(address, out T result, marshal); value[x] = result; } }