Struct UnsafeStream.Writer
Writes data into a buffer of an UnsafeStream.
Namespace: Unity.Collections.LowLevel.Unsafe
Assembly: Unity.Collections.dll
Syntax
public struct UnsafeStream.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).
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).
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.
When done using this writer, you must call <xref href="Unity.Collections.LowLevel.Unsafe.UnsafeStream.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.
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).