Struct UnsafeStream
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.LowLevel.Unsafe
Syntax
public struct UnsafeStream : IDisposable
Constructors
UnsafeStream(Int32, Allocator)
Constructs a new UnsafeStream using the specified type of memory allocation.
Declaration
public UnsafeStream(int foreachCount, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | foreachCount | |
Allocator | allocator |
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 UnsafeStream.Reader AsReader()
Returns
Type | Description |
---|---|
UnsafeStream.Reader |
AsWriter()
Returns writer instance.
Declaration
public UnsafeStream.Writer AsWriter()
Returns
Type | Description |
---|---|
UnsafeStream.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 UnsafeStream, NativeArray<Int32>, JobHandle, Allocator)
Schedule job to construct a new UnsafeStream using the specified type of memory allocation.
Declaration
public static JobHandle ScheduleConstruct(out UnsafeStream stream, NativeArray<int> lengthFromIndex0, JobHandle dependency, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
UnsafeStream | stream | |
NativeArray<Int32> | lengthFromIndex0 | |
JobHandle | dependency | All jobs spawned will depend on this JobHandle. |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
Returns
Type | Description |
---|---|
JobHandle |
ScheduleConstruct<T>(out UnsafeStream, NativeList<T>, JobHandle, Allocator)
Schedule job to construct a new UnsafeStream using the specified type of memory allocation.
Declaration
public static JobHandle ScheduleConstruct<T>(out UnsafeStream stream, NativeList<T> forEachCountFromList, JobHandle dependency, Allocator allocator)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
UnsafeStream | 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.