Class UnsafeUtilityExtensions
Provides utility methods for unsafe, untyped buffers.
Namespace: Unity.Collections.LowLevel.Unsafe
Assembly: Unity.Collections.dll
Syntax
public static class UnsafeUtilityExtensions
Methods
AddressOf<T>(in T)
Returns the address of a read-only reference.
Declaration
public static void* AddressOf<T>(in T value) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
T | value | A read-only reference. |
Returns
Type | Description |
---|---|
void* | A pointer to the referenced value. |
Type Parameters
Name | Description |
---|---|
T | The type of referenced value. |
AsRef<T>(in T)
Returns a read-write reference from a read-only reference.
in
arg (read-only reference) where a ref
arg (read-write reference) is expected.
Do not mutate the referenced value, as doing so may break the runtime's assumptions.
Declaration
public static ref T AsRef<T>(in T value) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
T | value | A read-only reference. |
Returns
Type | Description |
---|---|
T | A read-write reference to the value referenced by |
Type Parameters
Name | Description |
---|---|
T | The type of referenced value. |
ReadArrayElementBoundsChecked<T>(void*, int, int)
Reads an element from a buffer after bounds checking.
Declaration
public static T ReadArrayElementBoundsChecked<T>(void* source, int index, int capacity) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
void* | source | The buffer to read from. |
int | index | The index of the element. |
int | capacity | The buffer capacity (in number of elements). Used for the bounds checking. |
Returns
Type | Description |
---|---|
T | The element read from the buffer. |
Type Parameters
Name | Description |
---|---|
T | The type of element. |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | Thrown if the index is out of bounds. |
WriteArrayElementBoundsChecked<T>(void*, int, T, int)
Writes an element to a buffer after bounds checking.
Declaration
public static void WriteArrayElementBoundsChecked<T>(void* destination, int index, T value, int capacity) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
void* | destination | The buffer to write to. |
int | index | The index at which to store the element. |
T | value | The value to write. |
int | capacity | The buffer capacity (in number of elements). Used for the bounds checking. |
Type Parameters
Name | Description |
---|---|
T | The type of element. |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | Thrown if the index is out of bounds. |