NativeSlice<T>
Provides a view on a buffer of native memory most commonly acquired from a NativeArray<T>.
Read time 2 minutesLast updated 10 days ago
Definition
- Type: Struct
- Namespace: Unity.Collections
- Assembly: UnityEngine.CoreModule
- Implements: IEnumerable<T>, IEnumerable, IEquatable<NativeSlice<T>>
public struct NativeSlice<T> : IEnumerable<T>, IEnumerable, IEquatable<NativeSlice<T>> where T : struct
Remarks
A includes safety mechanisms for use with the job system. A doesn't own any memory allocations and can't be disposed, unlike a NativeArray<T>.
NativeSliceNativeSliceNativeArrayA supports a stride value and doesn't necessarily represent a contiguous memory range. The stride value determines the number of bytes from the first byte of the element to the first byte of the next element. The stride value must always be a multiple of the size of the type of the slice in bytes. The stride value allows you to skip elements from the underlying buffer.
NativeSliceBy default, the stride is set to the size of the type of slice in bytes. This means that the slice represents a contiguous memory range. If you don't need a stride and are only working with contiguous memory ranges, use NativeArray<T> instead.
Constructors
Constructor | Description |
|---|---|
| NativeSlice`1(Unity.Collections.NativeArray{`0}) | Constructs a new NativeSlice from a NativeArray. |
| NativeSlice`1(Unity.Collections.NativeArray{`0},System.Int32) | Constructs a new NativeSlice from a NativeArray, with a defined start index. |
| NativeSlice`1(Unity.Collections.NativeArray{`0},System.Int32,System.Int32) | Constructs a new NativeSlice of defined length |
| NativeSlice`1(Unity.Collections.NativeSlice{`0},System.Int32) | Constructs a new NativeSlice from another NativeSlice, with a defined start index. |
| NativeSlice`1(Unity.Collections.NativeSlice{`0},System.Int32,System.Int32) | Constructs a new NativeSlice of defined length |
Properties
Property | Description |
|---|---|
| this[] | Accesses NativeSlice<T> elements by index. |
| Length | Represents the number of elements in a NativeSlice<T>. |
| Stride | Gets the stride value for the NativeSlice<T> instance. |
Methods
Method | Description |
|---|---|
| CopyFrom | Copies all the elements from a NativeSlice<T> or managed array of the same length. |
| CopyTo | Copies all the elements of a NativeSlice<T> to a NativeArray<T> or managed array of the same length. |
| GetEnumerator | Gets an enumerator to iterate through the elements of a NativeSlice<T>. |
| SliceConvert | Reinterprets a NativeSlice with a different data type (type punning). |
| SliceWithStride | SliceWithStride. |
| ToArray | Converts a NativeSlice<T> to managed array. |