SafePointer
Represents a safe wrapper around an unmanaged memory pointer with bounds checking and shifting capabilities.
Construtores
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.
Propriedades
public IntPtr Pointer { get; }
value = safePointer.Pointer
Gets the current unmanaged memory pointer.
Métodos
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.
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.
Retorna: The underlying IntPtr value.
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.
Retorna: The value read from the pointer.
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.
public void Shift<TStruct>()
safePointer.Shift()
Shifts the pointer forward by the size of the specified structure type.
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.
Retorna: The structure read from the pointer.