Method TryBeginWrite
TryBeginWrite(int)
Allows faster serialization by batching bounds checking. When you know you will be writing multiple fields back-to-back and you know the total size, you can call TryBeginWrite() once on the total size, and then follow it with calls to WriteValue() instead of WriteValueSafe() for faster serialization.
Unsafe write operations will throw OverflowException in editor and development builds if you go past the point you've marked using TryBeginWrite(). In release builds, OverflowException will not be thrown for performance reasons, since the point of using TryBeginWrite is to avoid bounds checking in the following operations in release builds.
Declaration
public bool TryBeginWrite(int bytes)
Parameters
Type | Name | Description |
---|---|---|
int | bytes | Amount of bytes to write |
Returns
Type | Description |
---|---|
bool | True if the write is allowed, false otherwise |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If called while in a bitwise context |