private void UpdateBuffer()
 {
     using (var temp = new UnmanagedBlock(Marshal.SizeOf(mType)))
     {
         Marshal.StructureToPtr(mData, temp, true);
         mBuffer.Write(temp, 0, temp.Size);
     }
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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;
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
                }
            }
        }
示例#7
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();
                }
            }
        }
示例#8
0
        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();
                }
            }
        }
示例#9
0
 public void Read(IntPtr target, int readOffset, long bytesToRead) => UnmanagedBlock.Copy(Pointer, target, readOffset, 0, bytesToRead);
示例#10
0
 public void Write(IntPtr source, int writeOffset, long bytesToWrite) => UnmanagedBlock.Copy(source, Pointer, 0, writeOffset, bytesToWrite);