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. You must specify at least an allocation type to construct a usable container.
Warning: the IsCreated
property can't be used to determine whether a copy of a container is still valid.
If you dispose any copy of the container, the container storage is deallocated. However, the properties of
the other copies of the container (including the original) are not updated. As a result the IsCreated
property
of the copies still return true
even though the container storage has been deallocated.
Accessing the data of a native container that has been disposed throws a
Methods
AsReader()
Returns reader instance.
Declaration
public NativeStream.Reader AsReader()
Returns
Type | Description |
---|---|
NativeStream.Reader | Reader instance |
AsWriter()
Returns writer instance.
Declaration
public NativeStream.Writer AsWriter()
Returns
Type | Description |
---|---|
NativeStream.Writer | Writer instance. |
Count()
The current number of items in the container.
Declaration
public int Count()
Returns
Type | Description |
---|---|
Int32 | The 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.
IsEmpty()
Reports whether container is empty.
Declaration
public bool IsEmpty()
Returns
Type | Description |
---|---|
Boolean | True if this container empty. |
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 | The type of value. |
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 | The type of value. |
Remarks
The array is a copy of stream data.