/// <summary> /// Reads a unsigned integer from the memory block at the <paramref name="byteOffset"/>. /// </summary> /// <param name="byteOffset">An offset from the start of the memory block where the writing should start. /// Make sure the <paramref name="byteOffset"/> is properly aligned (usually 16-bits).</param> /// <returns>Returns the value.</returns> public uint ReadUintAt(int byteOffset) { Check.IfArgumentOutOfRange(byteOffset, 0, int.MaxValue, nameof(byteOffset)); var size = MemoryUtil.SizeOf(typeof(uint)); ValidateAccess(byteOffset, size); IntPtr location = IntPtr.Add(_memory, byteOffset); return(*(uint *)location.ToPointer()); }
/// <summary> /// Reads a unsigned integer from the memory block at the <paramref name="byteOffset"/>. /// </summary> /// <param name="byteOffset">An offset from the start of the memory block where the writing should start. /// Make sure the <paramref name="byteOffset"/> is properly aligned (usually 16-bits).</param> /// <returns>Returns the value.</returns> public uint ReadUintAt(int byteOffset) { Contract.Requires(byteOffset >= 0); var size = MemoryUtil.SizeOf(typeof(uint)); this.ValidateAccess(byteOffset, size); IntPtr location = IntPtr.Add(this.memory, byteOffset); return(*(uint *)location.ToPointer()); }
/// <summary> /// Writes a <paramref name="value"/> to the specified <paramref name="byteOffset"/>. /// </summary> /// <param name="byteOffset">An offset from the start of the memory block where the writing should start. /// Make sure the <paramref name="byteOffset"/> is properly aligned (usually 16-bits).</param> /// <param name="value">The value to write.</param> public void WriteUintAt(int byteOffset, uint value) { Check.IfArgumentOutOfRange(byteOffset, 0, int.MaxValue, nameof(byteOffset)); var size = MemoryUtil.SizeOf(typeof(uint)); ValidateAccess(byteOffset, size); IntPtr location = IntPtr.Add(_memory, byteOffset); *(uint *)location.ToPointer() = value; }
/// <summary> /// Writes a <paramref name="value"/> to the specified <paramref name="byteOffset"/>. /// </summary> /// <param name="byteOffset">An offset from the start of the memory block where the writing should start. /// Make sure the <paramref name="byteOffset"/> is properly aligned (usually 16-bits).</param> /// <param name="value">The value to write.</param> public void WriteUintAt(int byteOffset, uint value) { Contract.Requires(byteOffset >= 0); var size = MemoryUtil.SizeOf(typeof(uint)); this.ValidateAccess(byteOffset, size); IntPtr location = IntPtr.Add(this.memory, byteOffset); *(uint *)location.ToPointer() = value; }