Class UnsafeUtilityExtensions
Provides utility methods for unsafe, untyped buffers.
Namespace: Unity.Collections.LowLevel.Unsafe
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 : struct
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 : struct
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*, Int32, Int32)
Reads an element from a buffer after bounds checking.
Declaration
public static T ReadArrayElementBoundsChecked<T>(void *source, int index, int capacity)
Parameters
Type | Name | Description |
---|---|---|
Void* | source | The buffer to read from. |
Int32 | index | The index of the element. |
Int32 | 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*, Int32, T, Int32)
Writes an element to a buffer after bounds checking.
Declaration
public static void WriteArrayElementBoundsChecked<T>(void *destination, int index, T value, int capacity)
Parameters
Type | Name | Description |
---|---|---|
Void* | destination | The buffer to write to. |
Int32 | index | The index at which to store the element. |
T | value | The value to write. |
Int32 | 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. |