/// <summary> /// Reads the specified array T[] data from a memory location. /// </summary> /// <typeparam name="T">Type of a data to read</typeparam> /// <param name="source">Memory location to read from.</param> /// <param name="data">The data write to.</param> /// <param name="offset">The offset in the array to write to.</param> /// <param name="count">The number of T element to read from the memory location</param> /// <returns>source pointer + sizeof(T) * count</returns> public static IntPtr Read <T>(IntPtr source, T[] data, int offset, int count) where T : struct { unsafe { return((IntPtr)Interop.Read((void *)source, data, offset, count)); } }
/// <summary> /// Reads the specified T data from a memory location. /// </summary> /// <typeparam name="T">Type of a data to read</typeparam> /// <param name="source">Memory location to read from.</param> /// <param name="data">The data write to.</param> /// <returns>source pointer + sizeof(T)</returns> public static IntPtr ReadAndPosition <T>(IntPtr source, ref T data) where T : struct { unsafe { return((IntPtr)Interop.Read((void *)source, ref data)); } }
public T this[int index] { get { if (index >= Length) { throw new ArgumentOutOfRangeException(); } var res = new T(); unsafe { var bptr = (byte *)Pointer; bptr += index * sizeOfT; Interop.Read <T>(bptr, ref res); } return(res); } set { if (index >= Length) { throw new ArgumentOutOfRangeException(); } unsafe { var bptr = (byte *)Pointer; bptr += index * sizeOfT; Interop.Write <T>(bptr, ref value); } } }
public void Read([NotNull] T[] destination, int offset = 0) { if (offset + destination.Length > Length) { throw new ArgumentOutOfRangeException(); } unsafe { Interop.Read((void *)Pointer, destination, offset, destination.Length); } }
public void Read(T[] destination, int pointerByteOffset, int arrayOffset, int arrayLen) { if (arrayOffset + arrayLen > Length) { throw new ArgumentOutOfRangeException(); } unsafe { var ptr = (byte *)Pointer; ptr += pointerByteOffset; Interop.Read(ptr, destination, arrayOffset, arrayLen); } }