Unsafe.SubtractByteOffset Method

Definition

Overloads

SubtractByteOffset<T>(T, IntPtr)

Subtracts a byte offset from the given managed pointer.

SubtractByteOffset<T>(T, UIntPtr)

Subtracts a byte offset from the given managed pointer.

SubtractByteOffset<T>(T, IntPtr)

Source:
Unsafe.cs
Source:
Unsafe.cs
Source:
Unsafe.cs

Subtracts a byte offset from the given managed pointer.

public:
generic <typename T>
 static T % SubtractByteOffset(T % source, IntPtr byteOffset);
public static ref T SubtractByteOffset<T> (ref T source, IntPtr byteOffset);
static member SubtractByteOffset : 'T * nativeint -> 'T
Public Shared Function SubtractByteOffset(Of T) (ByRef source As T, byteOffset As IntPtr) As T

Type Parameters

T

The elemental type of the managed pointer.

Parameters

source
T

The managed pointer to subtract the offset from.

byteOffset
IntPtr

nativeint

The offset to subtract.

Returns

T

A new managed pointer that reflects the subtraction of the specified byte offset from the source pointer.

Remarks

The byteOffset parameter is the number of bytes to remove from the source pointer. For example, given a source pointer ptr of type ref int, the call Unsafe.SubtractByteOffset<int>(ref ptr, 20) will return a new pointer whose address points 20 bytes before ptr.

If byteOffset is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call Unsafe.SubtractByteOffset<int>(ref ptr, a * b), the caller must ensure the intermediate value a * b does not overflow the bounds of IntPtr.

Applies to

SubtractByteOffset<T>(T, UIntPtr)

Source:
Unsafe.cs
Source:
Unsafe.cs
Source:
Unsafe.cs

Important

This API is not CLS-compliant.

Subtracts a byte offset from the given managed pointer.

public:
generic <typename T>
 static T % SubtractByteOffset(T % source, UIntPtr byteOffset);
public static ref T SubtractByteOffset<T> (ref T source, nuint byteOffset);
[System.CLSCompliant(false)]
public static ref T SubtractByteOffset<T> (ref T source, UIntPtr byteOffset);
static member SubtractByteOffset : 'T * unativeint -> 'T
[<System.CLSCompliant(false)>]
static member SubtractByteOffset : 'T * unativeint -> 'T
Public Shared Function SubtractByteOffset(Of T) (ByRef source As T, byteOffset As UIntPtr) As T

Type Parameters

T

The elemental type of the managed pointer.

Parameters

source
T

The managed pointer to subtract the offset from.

byteOffset
UIntPtr

nuint

unativeint

The offset to subtract.

Returns

T

A new managed pointer that reflects the subtraction of the specified byte offset from the source pointer.

Attributes

Remarks

The byteOffset parameter is the number of bytes to subtract from the source pointer. For example, given a source pointer ptr of type ref int, the call Unsafe.SubtractByteOffset<int>(ref ptr, (nuint)20) will return a new pointer whose address points 20 bytes before ptr.

If byteOffset is a calculated value rather than a hardcoded literal, callers should consider the possibility of integer overflow. For example, in the call Unsafe.SubtractByteOffset<int>(ref ptr, a * b), the caller must ensure the intermediate value a * b does not overflow the bounds of UIntPtr.

Applies to