Table of Contents

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

value T

The variable whose memory address is to be obtained.

Returns

void*

A pointer to the memory address of the specified variable.

Type Parameters

T

Represents 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

ptr void*

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

T

Specifies 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

span ReadOnlySpan<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

T

The 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

span Span<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

T

The 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

ptr void*

Points to the start of the unmanaged array from which the element is read.

index nint

Indicates 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

T

Specifies 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

ptr void*

Points to the start of the unmanaged array from which the element is read.

index nuint

Indicates 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

T

Specifies 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

ptr void*

Points to the start of the unmanaged array from which the element is read.

index nint

Indicates 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

T

Specifies 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

ptr void*

Points to the start of the unmanaged array from which the element is read.

index nuint

Indicates 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

T

Specifies 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

ptr void*

Points to the start of the array from which an element will be read.

index nint

Indicates 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

T

Specifies 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

ptr void*

Points to the start of the array from which an element will be read.

index nuint

Indicates 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

T

Specifies 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

ptr void*

Points to the beginning of the unmanaged array where the value will be written.

index nint

Indicates the position in the array where the value should be stored.

value T

Represents the value to be written to the specified index of the array.

Type Parameters

T

Specifies 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

ptr void*

Points to the beginning of the unmanaged array where the value will be written.

index nuint

Indicates the position in the array where the value should be stored.

value T

Represents the value to be written to the specified index of the array.

Type Parameters

T

Specifies the type of the value being written to the array, which must be an unmanaged type.