public unsafe void Write <T>(ulong byteOffset, T value) where T : struct { if (this._numBytes == SafeBuffer.Uninitialized) { throw SafeBuffer.NotInitialized(); } uint sizeofT = Marshal.SizeOfType(typeof(T)); byte *ptr = (byte *)((IntPtr)(void *)this.handle + (IntPtr)byteOffset); this.SpaceCheck(ptr, (ulong)sizeofT); bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { this.DangerousAddRef(ref success); SafeBuffer.GenericStructureToPtr <T>(ref value, ptr, sizeofT); } finally { if (success) { this.DangerousRelease(); } } }
public void Write <T>(ulong byteOffset, T value) where T : struct { if (_numBytes == Uninitialized) { throw NotInitialized(); } uint sizeofT = Marshal.SizeOfType(typeof(T)); byte *ptr = (byte *)handle + byteOffset; SpaceCheck(ptr, sizeofT); // *((T*) (_ptr + byteOffset)) = value; bool mustCallRelease = false; RuntimeHelpers.PrepareConstrainedRegions(); try { DangerousAddRef(ref mustCallRelease); GenericStructureToPtr(ref value, ptr, sizeofT); } finally { if (mustCallRelease) { DangerousRelease(); } } }
public unsafe void Write <T>(ulong byteOffset, T value) where T : struct { if (this._numBytes == SafeBuffer.Uninitialized) { throw SafeBuffer.NotInitialized(); } uint num = Marshal.SizeOfType(typeof(T)); byte *ptr = (byte *)((void *)this.handle) + byteOffset; this.SpaceCheck(ptr, (ulong)num); bool flag = false; RuntimeHelpers.PrepareConstrainedRegions(); try { base.DangerousAddRef(ref flag); SafeBuffer.GenericStructureToPtr <T>(ref value, ptr, num); } finally { if (flag) { base.DangerousRelease(); } } }
public void ReadArray <T>(ulong byteOffset, T[] array, int index, int count) where T : struct { if (array == null) { throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); } if (index < 0) { throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (count < 0) { throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (array.Length - index < count) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); } Contract.EndContractBlock(); if (_numBytes == Uninitialized) { throw NotInitialized(); } uint sizeofT = Marshal.SizeOfType(typeof(T)); uint alignedSizeofT = Marshal.AlignedSizeOf <T>(); byte *ptr = (byte *)handle + byteOffset; SpaceCheck(ptr, checked ((ulong)(alignedSizeofT * count))); bool mustCallRelease = false; RuntimeHelpers.PrepareConstrainedRegions(); try { DangerousAddRef(ref mustCallRelease); for (int i = 0; i < count; i++) { unsafe { GenericPtrToStructure <T>(ptr + alignedSizeofT * i, out array[i + index], sizeofT); } } } finally { if (mustCallRelease) { DangerousRelease(); } } }
public void WriteArray <T>(ulong byteOffset, T[] array, int index, int count) where T : struct { if (array == null) { throw new ArgumentNullException(nameof(array), SR.ArgumentNull_Buffer); } if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); } if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); } if (array.Length - index < count) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (_numBytes == Uninitialized) { throw NotInitialized(); } uint sizeofT = Marshal.SizeOfType(typeof(T)); uint alignedSizeofT = Marshal.AlignedSizeOf <T>(); byte *ptr = (byte *)handle + byteOffset; SpaceCheck(ptr, checked ((ulong)(alignedSizeofT * count))); bool mustCallRelease = false; RuntimeHelpers.PrepareConstrainedRegions(); try { DangerousAddRef(ref mustCallRelease); for (int i = 0; i < count; i++) { unsafe { GenericStructureToPtr(ref array[i + index], ptr + alignedSizeofT * i, sizeofT); } } } finally { if (mustCallRelease) { DangerousRelease(); } } }
public unsafe void WriteArray <T>(ulong byteOffset, T[] array, int index, int count) where T : struct { if (array == null) { throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); } if (index < 0) { throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (count < 0) { throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (array.Length - index < count) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); } if (this._numBytes == SafeBuffer.Uninitialized) { throw SafeBuffer.NotInitialized(); } uint sizeofT = Marshal.SizeOfType(typeof(T)); uint num = Marshal.AlignedSizeOf <T>(); byte *ptr = (byte *)((IntPtr)(void *)this.handle + (IntPtr)byteOffset); this.SpaceCheck(ptr, checked ((ulong)((long)num * (long)count))); bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { this.DangerousAddRef(ref success); for (int index1 = 0; index1 < count; ++index1) { SafeBuffer.GenericStructureToPtr <T>(ref array[index1 + index], ptr + (long)num * (long)index1, sizeofT); } } finally { if (success) { this.DangerousRelease(); } } }
public unsafe void ReadArray <T>(ulong byteOffset, T[] array, int index, int count) where T : struct { if (array == null) { throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); } if (index < 0) { throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (count < 0) { throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (array.Length - index < count) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); } if (this._numBytes == SafeBuffer.Uninitialized) { throw SafeBuffer.NotInitialized(); } uint sizeofT = Marshal.SizeOfType(typeof(T)); uint num = Marshal.AlignedSizeOf <T>(); byte *ptr = (byte *)((void *)this.handle) + byteOffset; this.SpaceCheck(ptr, checked (unchecked ((ulong)num) * (ulong)(unchecked ((long)count)))); bool flag = false; RuntimeHelpers.PrepareConstrainedRegions(); try { base.DangerousAddRef(ref flag); for (int i = 0; i < count; i++) { SafeBuffer.GenericPtrToStructure <T>(ptr + (ulong)num * (ulong)((long)i), out array[i + index], sizeofT); } } finally { if (flag) { base.DangerousRelease(); } } }