SafePointer

Ecng.Interop

Represents a safe wrapper around an unmanaged memory pointer with bounds checking and shifting capabilities.

构造函数

SafePointer
public SafePointer(IntPtr pointer, int? size)
safePointer = SafePointer(pointer, size)

Initializes a new instance of the SafePointer struct with a specified pointer and optional size.

pointer
The unmanaged memory pointer to wrap. Must not be Zero.
size
The optional size of the memory block in bytes. If specified, must be non-negative.

属性

Pointer
public IntPtr Pointer { get; }
value = safePointer.Pointer

Gets the current unmanaged memory pointer.

方法

CopyTo
public void CopyTo(byte[] buffer, bool autoShift)
safePointer.CopyTo(buffer, autoShift)

Copies data from the current pointer position to a byte array.

buffer
The target byte array to copy data into.
autoShift
If true, shifts the pointer by the length of the copied data after copying.
CopyTo
public void CopyTo(byte[] buffer, int offset, int length, bool autoShift)
safePointer.CopyTo(buffer, offset, length, autoShift)

Copies a specified amount of data from the current pointer position to a byte array.

buffer
The target byte array to copy data into.
offset
The starting index in the buffer where data should be copied.
length
The number of bytes to copy.
autoShift
If true, shifts the pointer by after copying.
op_Implicit(IntPtr) : IntPtr

Implicitly converts a SafePointer to an IntPtr.

pointer
The SafePointer instance to convert.

返回值: The underlying IntPtr value.

Read``1
public TValue Read<TValue>(bool autoShift)
result = safePointer.Read(autoShift)

Reads a value of type from the current pointer position.

autoShift
If true, shifts the pointer by the size of after reading.

返回值: The value read from the pointer.

Shift
public void Shift(int offset)
safePointer.Shift(offset)

Shifts the pointer forward by the specified offset in bytes.

offset
The number of bytes to shift the pointer.
Shift``1
public void Shift<TStruct>()
safePointer.Shift()

Shifts the pointer forward by the size of the specified structure type.

ToStruct``1
public TStruct ToStruct<TStruct>(bool autoShift)
result = safePointer.ToStruct(autoShift)

Reads a structure of type from the current pointer position.

autoShift
If true, shifts the pointer by the size of after reading.

返回值: The structure read from the pointer.