private void UpdateBuffer() { using (var temp = new UnmanagedBlock(Marshal.SizeOf(mType))) { Marshal.StructureToPtr(mData, temp, true); mBuffer.Write(temp, 0, temp.Size); } }
public void Write(IntPtr source, int writeOffset, long bytesToWrite) { if (!mWritable) { throw new AccessViolationException("The underlying memory block does not allow writing."); } UnmanagedBlock.Copy(source, Pointer, 0, writeOffset, bytesToWrite); }
public void Read(IntPtr target, int readOffset, long bytesToRead) { if (!mReadable) { throw new AccessViolationException("The underlying memory block does not allow reading."); } UnmanagedBlock.Copy(Pointer, target, readOffset, 0, bytesToRead); }
public override unsafe void Write(byte[] buffer, int offset, int count) { fixed(void *pBuffer = buffer) { var bufferPointer = new IntPtr(pBuffer); var targetPointer = mMemory.GetPointer(); var length = Math.Min(count, mMemory.Size - mCurrentOffset); UnmanagedBlock.Copy(bufferPointer, targetPointer, offset, (int)mCurrentOffset, length); mCurrentOffset += length; } }
public override unsafe int Read(byte[] buffer, int offset, int count) { fixed(void *pBuffer = buffer) { var bufferPointer = new IntPtr(pBuffer); var sourcePointer = mMemory.GetPointer(); var length = Math.Min(count, mMemory.Size - mCurrentOffset); UnmanagedBlock.Copy(sourcePointer, bufferPointer, (int)mCurrentOffset, offset, length); mCurrentOffset += length; return((int)length); } }
public void Write(IntPtr source, int writeOffset, long bytesToWrite) { var buffer = GetBuffer(); DataBox mappedResource = null; try { mappedResource = Device.ImmediateContext.MapSubresource(buffer, MapMode.WriteDiscard, MapFlags.None); UnmanagedBlock.Copy(source, mappedResource.Data.DataPointer, 0, writeOffset, bytesToWrite); } finally { if (mappedResource != null) { Device.ImmediateContext.UnmapSubresource(buffer, 0); } } }
public static void CopyTo <T>(this IReadableMemory memory, [NotNull] T[] targetArray) where T : struct { if (targetArray == null) { throw new ArgumentNullException(nameof(targetArray)); } var targetArrayHandle = default(GCHandle); try { targetArrayHandle = GCHandle.Alloc(targetArray, GCHandleType.Pinned); UnmanagedBlock.Copy(memory.GetPointer(), targetArrayHandle.AddrOfPinnedObject(), 0, 0, memory.Size); } finally { if (targetArrayHandle.IsAllocated) { targetArrayHandle.Free(); } } }
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(); } } }
public void Read(IntPtr target, int readOffset, long bytesToRead) => UnmanagedBlock.Copy(Pointer, target, readOffset, 0, bytesToRead);
public void Write(IntPtr source, int writeOffset, long bytesToWrite) => UnmanagedBlock.Copy(source, Pointer, 0, writeOffset, bytesToWrite);