Struct NativeStream
A deterministic data streaming supporting parallel reading and parallel writing. Allows you to write different types or arrays into a single stream.
Namespace: Unity.Collections
Syntax
public struct NativeStream : IDisposable
Constructors
NativeStream(Int32, Allocator)
Constructs a new NativeStream using the specified type of memory allocation.
Declaration
public NativeStream(int foreachCount, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | foreachCount | |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Properties
ForEachCount
Declaration
public int ForEachCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
IsCreated
Reports whether memory for the container is allocated.
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this container object's internal storage has been allocated. |
Remarks
Note that the container storage is not created if you use the default constructor.
Methods
AsReader()
Returns reader instance.
Declaration
public NativeStream.Reader AsReader()
Returns
Type | Description |
---|---|
NativeStream.Reader |
AsWriter()
Returns writer instance.
Declaration
public NativeStream.Writer AsWriter()
Returns
Type | Description |
---|---|
NativeStream.Writer |
ComputeItemCount()
Compute item count.
Declaration
public int ComputeItemCount()
Returns
Type | Description |
---|---|
Int32 | Item count. |
Dispose()
Disposes of this stream and deallocates its memory immediately.
Declaration
public void Dispose()
Dispose(JobHandle)
Safely disposes of this container and deallocates its memory when the jobs that use it have completed.
Declaration
public JobHandle Dispose(JobHandle dependency)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | dependency | All jobs spawned will depend on this JobHandle. |
Returns
Type | Description |
---|---|
JobHandle | A new job handle containing the prior handles as well as the handle for the job that deletes the container. |
Remarks
You can call this function dispose of the container immediately after scheduling the job. Pass
the JobHandle returned by
the Job.Schedule
method using the jobHandle
parameter so the job scheduler can dispose the container after all jobs
using it have run.
ScheduleConstruct(out NativeStream, NativeArray<Int32>, JobHandle, Allocator)
Schedule job to construct a new NativeStream using the specified type of memory allocation.
Declaration
public static JobHandle ScheduleConstruct(out NativeStream stream, NativeArray<int> lengthFromIndex0, JobHandle dependency, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
NativeStream | stream | |
NativeArray<Int32> | lengthFromIndex0 | |
JobHandle | dependency | |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
JobHandle |
ScheduleConstruct<T>(out NativeStream, NativeList<T>, JobHandle, Allocator)
Schedule job to construct a new NativeStream using the specified type of memory allocation.
Declaration
public static JobHandle ScheduleConstruct<T>(out NativeStream stream, NativeList<T> forEachCountFromList, JobHandle dependency, Allocator allocator)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
NativeStream | stream | |
NativeList<T> | forEachCountFromList | |
JobHandle | dependency | All jobs spawned will depend on this JobHandle. |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
JobHandle |
Type Parameters
Name | Description |
---|---|
T |
ToNativeArray<T>(Allocator)
Copies stream data into NativeArray.
Declaration
public NativeArray<T> ToNativeArray<T>(Allocator allocator)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
NativeArray<T> | A new NativeArray, allocated with the given strategy and wrapping the stream data. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
The array is a copy of stream data.