public static void Read([NotNull] this IReadable readableMemory, [NotNull] IWritableMemory targetMemory) { if (readableMemory == null) { throw new ArgumentNullException(nameof(readableMemory)); } if (targetMemory == null) { throw new ArgumentNullException(nameof(targetMemory)); } readableMemory.Read(targetMemory.GetPointer(), 0, targetMemory.Size); }
public T this[int index] { set { if (index < 0 || index >= mLength) { throw new IndexOutOfRangeException(); } var offset = index * mSizeOfT; var address = mMemory.GetPointer() + offset; Marshal.StructureToPtr(value, address, true); } }
public WriteOnlyMemoryWindow([NotNull] IWritableMemory memoryBlock, int offset, long size) { if (memoryBlock == null) { throw new ArgumentNullException(nameof(memoryBlock)); } if (offset < 0) { throw new ArgumentOutOfRangeException(nameof(offset)); } if (size > memoryBlock.Size - offset) { throw new ArgumentOutOfRangeException(nameof(size), "The window size is larger than the size of the target block."); } Pointer = memoryBlock.GetPointer() + offset; Size = size; }
public static void FromArray <T>(this IWritableMemory memory, [NotNull] T[] sourceArray) where T : struct { if (sourceArray == null) { throw new ArgumentNullException(nameof(sourceArray)); } var sourceArrayHandle = default(GCHandle); try { sourceArrayHandle = GCHandle.Alloc(sourceArray, GCHandleType.Pinned); UnmanagedBlock.Copy(sourceArrayHandle.AddrOfPinnedObject(), memory.GetPointer(), 0, 0, memory.Size); } finally { if (sourceArrayHandle.IsAllocated) { sourceArrayHandle.Free(); } } }