Struct NativeStream.Writer
Writes data into a buffer of a NativeStream.
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
[NativeContainer]
[NativeContainerSupportsMinMaxWriteRestriction]
public struct NativeStream.Writer
Remarks
An individual writer can only be used for one buffer of one stream. Do not create more than one writer for an individual buffer.
Properties
ForEachCount
The number of buffers in the stream of this writer.
Declaration
public int ForEachCount { get; }
Property Value
Type | Description |
---|---|
int | The number of buffers in the stream of this writer. |
Methods
Allocate(int)
Allocate space in a buffer.
Declaration
public byte* Allocate(int size)
Parameters
Type | Name | Description |
---|---|---|
int | size | The number of bytes to allocate. |
Returns
Type | Description |
---|---|
byte* | The allocation. |
Remarks
The space is allocated in the buffer which was specified with BeginForEachIndex(int).
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if BeginForEachIndex was not called. |
ArgumentException | Thrown when the NativeStream.Writer instance has been passed by value instead of by reference. |
Allocate<T>()
Allocate space in a buffer.
Declaration
public ref T Allocate<T>() where T : unmanaged
Returns
Type | Description |
---|---|
T | A reference to the allocation. |
Type Parameters
Name | Description |
---|---|
T | The type of value to allocate space for. |
Remarks
The space is allocated in the buffer which was specified with BeginForEachIndex(int).
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if BeginForEachIndex was not called. |
ArgumentException | Thrown when the NativeStream.Writer instance has been passed by value instead of by reference. |
BeginForEachIndex(int)
Readies this writer to write to a particular buffer of the stream.
Declaration
public void BeginForEachIndex(int foreachIndex)
Parameters
Type | Name | Description |
---|---|---|
int | foreachIndex | The index of the buffer to write. |
Remarks
Must be called before using this writer. For an individual writer, call this method only once.
After calling BeginForEachIndex on this writer, passing this writer into functions must be passed by reference.
When done using this writer, you must call <xref href="Unity.Collections.NativeStream.Writer.EndForEachIndex" data-throw-if-not-resolved="false"></xref>.
EndForEachIndex()
Readies the buffer written by this writer for reading.
Declaration
public void EndForEachIndex()
Remarks
Must be called before reading the buffer written by this writer.
PatchMinMaxRange(int)
For internal use only.
Declaration
public void PatchMinMaxRange(int foreEachIndex)
Parameters
Type | Name | Description |
---|---|---|
int | foreEachIndex |
Write<T>(T)
Write a value to a buffer.
Declaration
public void Write<T>(T value) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to write. |
Type Parameters
Name | Description |
---|---|
T | The type of value to write. |
Remarks
The value is written to the buffer which was specified with BeginForEachIndex(int).
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if BeginForEachIndex was not called. |
ArgumentException | Thrown when the NativeStream.Writer instance has been passed by value instead of by reference. |