Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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

public struct NativeSlice<T> : IEnumerable<T>, IEnumerable, IEquatable<NativeSlice<T>> where T : struct

Remarks

A
NativeSlice
includes safety mechanisms for use with the job system. A
NativeSlice
doesn't own any memory allocations and can't be disposed, unlike a
NativeArray
NativeArray<T>.
A
NativeSlice
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.
By 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
length
, from a NativeArray with a defined start index.
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
length
, from another NativeSlice, with a defined start index.

Properties

Property

Description

this[]Accesses NativeSlice<T> elements by index.
LengthRepresents the number of elements in a NativeSlice<T>.
StrideGets the stride value for the NativeSlice<T> instance.

Methods

Method

Description

CopyFromCopies all the elements from a NativeSlice<T> or managed array of the same length.
CopyToCopies all the elements of a NativeSlice<T> to a NativeArray<T> or managed array of the same length.
GetEnumeratorGets an enumerator to iterate through the elements of a NativeSlice<T>.
SliceConvertReinterprets a NativeSlice with a different data type (type punning).
SliceWithStrideSliceWithStride.
ToArrayConverts a NativeSlice<T> to managed array.