Class UnsafeUtility
- Namespace
- Misaki.HighPerformance.LowLevel.Utilities
- Assembly
- Misaki.HighPerformance.LowLevel.dll
public static class UnsafeUtility
- Inheritance
-
UnsafeUtility
- Inherited Members
Methods
AddressOf<T>(ref T)
Returns the address of a specified variable in memory.
public static void* AddressOf<T>(ref T value) where T : unmanaged
Parameters
valueTThe variable whose memory address is to be obtained.
Returns
- void*
A pointer to the memory address of the specified variable.
Type Parameters
TRepresents the type of the variable whose address is being retrieved.
AsRef<T>(void*)
Converts a pointer to a reference of a specified type.
public static ref T AsRef<T>(void* ptr) where T : unmanaged
Parameters
ptrvoid*Represents the memory address to be converted into a reference.
Returns
- T
Returns a reference of the specified type pointing to the given memory address.
Type Parameters
TSpecifies the type of the reference to be created from the pointer.
GetUnsafePtr<T>(ReadOnlySpan<T>)
Returns a pointer to the first element of the specified span. This method enables direct, unsafe access to the underlying data of the span.
public static T* GetUnsafePtr<T>(this ReadOnlySpan<T> span) where T : unmanaged
Parameters
spanReadOnlySpan<T>The span whose underlying data pointer is to be obtained.
Returns
- T*
A pointer to the first element of the span. If the span is empty, the returned pointer is undefined and must not be dereferenced.
Type Parameters
TThe type of elements in the span. Must be an unmanaged type.
GetUnsafePtr<T>(Span<T>)
Returns a pointer to the first element of the specified span. This method enables direct, unsafe access to the underlying data of the span.
public static T* GetUnsafePtr<T>(this Span<T> span) where T : unmanaged
Parameters
spanSpan<T>The span whose underlying data pointer is to be obtained.
Returns
- T*
A pointer to the first element of the span. If the span is empty, the returned pointer is undefined and must not be dereferenced.
Type Parameters
TThe type of elements in the span. Must be an unmanaged type.
ReadArrayElementRef<T>(void*, nint)
Reads an element from an unmanaged array using a pointer and index, returning a reference to the element.
public static ref T ReadArrayElementRef<T>(void* ptr, nint index) where T : unmanaged
Parameters
ptrvoid*Points to the start of the unmanaged array from which the element is read.
indexnintIndicates the position of the element to be accessed in the array.
Returns
- T
A reference to the specified element in the unmanaged array.
Type Parameters
TSpecifies the type of the elements in the unmanaged array.
ReadArrayElementRef<T>(void*, nuint)
Reads an element from an unmanaged array using a pointer and index, returning a reference to the element.
public static ref T ReadArrayElementRef<T>(void* ptr, nuint index) where T : unmanaged
Parameters
ptrvoid*Points to the start of the unmanaged array from which the element is read.
indexnuintIndicates the position of the element to be accessed in the array.
Returns
- T
A reference to the specified element in the unmanaged array.
Type Parameters
TSpecifies the type of the elements in the unmanaged array.
ReadArrayElementUnsafe<T>(void*, nint)
Reads an element from an unmanaged array at a specified index using a pointer.
public static T* ReadArrayElementUnsafe<T>(void* ptr, nint index) where T : unmanaged
Parameters
ptrvoid*Points to the start of the unmanaged array from which the element is read.
indexnintIndicates the position of the element to be accessed within the array.
Returns
- T*
Returns a pointer to the element located at the specified index.
Type Parameters
TSpecifies the type of elements in the unmanaged array.
ReadArrayElementUnsafe<T>(void*, nuint)
Reads an element from an unmanaged array at a specified index using a pointer.
public static T* ReadArrayElementUnsafe<T>(void* ptr, nuint index) where T : unmanaged
Parameters
ptrvoid*Points to the start of the unmanaged array from which the element is read.
indexnuintIndicates the position of the element to be accessed within the array.
Returns
- T*
Returns a pointer to the element located at the specified index.
Type Parameters
TSpecifies the type of elements in the unmanaged array.
ReadArrayElement<T>(void*, nint)
Reads an element from an array at a specified index using a pointer to the array.
public static T ReadArrayElement<T>(void* ptr, nint index) where T : unmanaged
Parameters
ptrvoid*Points to the start of the array from which an element will be read.
indexnintIndicates the position of the element to be accessed within the array.
Returns
- T
The element located at the specified index in the array.
Type Parameters
TSpecifies the type of the elements in the array, which must be unmanaged.
ReadArrayElement<T>(void*, nuint)
Reads an element from an array at a specified index using a pointer to the array.
public static T ReadArrayElement<T>(void* ptr, nuint index) where T : unmanaged
Parameters
ptrvoid*Points to the start of the array from which an element will be read.
indexnuintIndicates the position of the element to be accessed within the array.
Returns
- T
The element located at the specified index in the array.
Type Parameters
TSpecifies the type of the elements in the array, which must be unmanaged.
WriteArrayElement<T>(void*, nint, T)
Writes a value to a specified index of an unmanaged array using a pointer.
public static void WriteArrayElement<T>(void* ptr, nint index, T value) where T : unmanaged
Parameters
ptrvoid*Points to the beginning of the unmanaged array where the value will be written.
indexnintIndicates the position in the array where the value should be stored.
valueTRepresents the value to be written to the specified index of the array.
Type Parameters
TSpecifies the type of the value being written to the array, which must be an unmanaged type.
WriteArrayElement<T>(void*, nuint, T)
Writes a value to a specified index of an unmanaged array using a pointer.
public static void WriteArrayElement<T>(void* ptr, nuint index, T value) where T : unmanaged
Parameters
ptrvoid*Points to the beginning of the unmanaged array where the value will be written.
indexnuintIndicates the position in the array where the value should be stored.
valueTRepresents the value to be written to the specified index of the array.
Type Parameters
TSpecifies the type of the value being written to the array, which must be an unmanaged type.