Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

UnsafeStream

struct in Unity.Collections.LowLevel.Unsafe


Implements interfaces:INativeDisposable

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

A set of untyped, append-only buffers. Allows for concurrent reading and concurrent writing without synchronization.

As long as each individual buffer is written in one thread and read in one thread, multiple threads can read and write the stream concurrently, "e.g." while thread "A" reads from buffer "X" of a stream, thread "B" can read from buffer "Y" of the same stream.

Each buffer is stored as a chain of blocks. When a write exceeds a buffer's current capacity, another block is allocated and added to the end of the chain. Effectively, expanding the buffer never requires copying the existing data (unlike, for example, with NativeList<T0>).

All writing to a stream should be completed before the stream is first read. Do not write to a stream after the first read.

Writing is done with Writer, and reading is done with Reader. An individual reader or writer cannot be used concurrently across threads. Each thread must use its own.

The data written to an individual buffer can be heterogeneous in type, and the data written to different buffers of a stream can be entirely different in type, number, and order. Just make sure that the code reading from a particular buffer knows what to expect to read from it.

Properties

Property Description
ForEachCount The number of buffers in this stream.
IsCreated Whether this stream has been allocated (and not yet deallocated).

Constructors

Constructor Description
UnsafeStream Initializes and returns an instance of UnsafeStream.

Public Methods

Method Description
AsReader Returns a reader of this stream.
AsWriter Returns a writer of this stream.
Count Returns the total number of items in the buffers of this stream.
Dispose Releases all resources (memory).
IsEmpty Returns true if this stream is empty.
ToNativeArray Returns a new NativeArray copy of this stream's data.

Static Methods

Method Description
ScheduleConstruct Creates and schedules a job to allocate a new stream.