Struct UnsafeStream
A deterministic data streaming supporting parallel reading and parallel writings, without any thread safety check features. Allows you to write different types or arrays into a single stream.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafeStream : INativeDisposable, 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. 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.
Methods
AsReader()
Returns reader instance.
Declaration
public UnsafeStream.Reader AsReader()
Returns
Type | Description |
---|---|
UnsafeStream.Reader | Reader instance |
AsWriter()
Returns writer instance.
Declaration
public UnsafeStream.Writer AsWriter()
Returns
Type | Description |
---|---|
UnsafeStream.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 inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | 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. |
Implements
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 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 | The type of value. |
Remarks
The array is a copy of stream data.