Struct UnsafeStream.Writer
Writes data into a buffer of an UnsafeStream.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct 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 readonly int ForEachCount { get; }
Property Value
| Type | Description |
|---|---|
| Int32 | The number of buffers in the stream of this writer. |
Methods
Allocate(Int32)
Allocate space in a buffer.
Declaration
public byte *Allocate(int size)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | 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(Int32).
Allocate<T>()
Allocate space in a buffer.
Declaration
public ref T Allocate<T>()
where T : struct
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(Int32).
BeginForEachIndex(Int32)
Readies this writer to write to a particular buffer of the stream.
Declaration
public void BeginForEachIndex(int foreachIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | 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 EndForEachIndex().
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 : struct
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(Int32).