NativeArray<T>
Provides a buffer of native memory to managed code, making it possible to share data between managed and native code without marshalling costs.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Struct
- Namespace: Unity.Collections
- Assembly: UnityEngine.CoreModule
- Implements: IDisposable, IEnumerable<T>, IEnumerable, IEquatable<NativeArray<T>>
public struct NativeArray<T> : IDisposable, IEnumerable<T>, IEnumerable, IEquatable<NativeArray<T>> where T : struct
Remarks
A NativeArray instance provides systems that means you can use them safely in jobs. A NativeArray also has automatic memory leak tracking.
Constructors
Constructor | Description |
|---|---|
| NativeArray`1(`0[],Unity.Collections.Allocator) | Creates a NativeArray from an array of elements. |
| NativeArray`1(System.Int32,Unity.Collections.Allocator,Unity.Collections.NativeArrayOptions) | Creates a new NativeArray and allocates enough memory to fit the provided amount of elements. |
| NativeArray`1(Unity.Collections.NativeArray{`0},Unity.Collections.Allocator) | Creates a NativeArray from an existing NativeArray. |
Properties
Property | Description |
|---|---|
| IsCreated | Indicates that a NativeArray<T> has an allocated memory buffer. |
| this[] | Access NativeArray<T> elements by index. |
| Length | Number of elements in a NativeArray<T>. |
Methods
Method | Description |
|---|---|
| AsReadOnly | Casts a NativeArray<T> to read-only array. |
| AsReadOnlySpan | Exposes NativeArray<T> data as a |
| AsSpan | Exposes NativeArray<T> data as a |
| CopyFrom | Copies all the elements from a NativeArray<T> or a managed array of the same length. |
| CopyTo | Copies all the elements to another NativeArray<T> or a managed array of the same length. |
| Dispose | Disposes a NativeArray<T>. |
| Equals | Compares a NativeArray<T> instance and an object. |
| GetEnumerator | Gets an enumerator. |
| GetHashCode | Gets a hash code for the current instance. |
| GetSubArray | Gets a view into an array starting at the specified index. |
| Reinterpret | Reinterpret a NativeArray<T> with a different data type (type punning). |
| ReinterpretLoad | Reinterpret and load data starting at underlying index as a different type. |
| ReinterpretStore | Reinterpret and store data starting at underlying index as a different type. |
| ToArray | Convert a NativeArray<T> to an array. |
Static Methods
Method | Description |
|---|---|
| Copy | Copies a range of elements from a source array to a destination array, starting from the source index and copying them to the destination index. |
Structs
Struct | Description |
|---|---|
| NativeArray<T>.ReadOnly | Represents a NativeArray<T> interface constrained to read-only operations. |