Struct InputEventBuffer
A buffer of raw memory holding a sequence of InputEvent.
Namespace: UnityEngine.InputSystem.LowLevel
Syntax
public struct InputEventBuffer : IEnumerable<InputEventPtr>, IEnumerable, IDisposable, ICloneable
Remarks
Note that event buffers are not thread-safe. It is not safe to write events to the buffer concurrently from multiple threads. It is, however, safe to traverse the contents of an existing buffer from multiple threads as long as it is not mutated at the same time.
Constructors
InputEventBuffer(NativeArray<Byte>, Int32, Int32)
Declaration
public InputEventBuffer(NativeArray<byte> buffer, int eventCount, int sizeInBytes = -1)
Parameters
Type | Name | Description |
---|---|---|
NativeArray<Byte> | buffer | |
Int32 | eventCount | |
Int32 | sizeInBytes |
InputEventBuffer(InputEvent*, Int32, Int32, Int32)
Declaration
public InputEventBuffer(InputEvent*eventPtr, int eventCount, int sizeInBytes = -1, int capacityInBytes = -1)
Parameters
Type | Name | Description |
---|---|---|
InputEvent* | eventPtr | |
Int32 | eventCount | |
Int32 | sizeInBytes | |
Int32 | capacityInBytes |
Fields
BufferSizeUnknown
Declaration
public const long BufferSizeUnknown = -1L
Field Value
Type | Description |
---|---|
Int64 |
Properties
bufferPtr
Pointer to the first event in the buffer.
Declaration
public InputEventPtr bufferPtr { get; }
Property Value
Type | Description |
---|---|
InputEventPtr | Pointer to first event in buffer. |
capacityInBytes
Total size of allocated memory in bytes. This value minus sizeInBytes is the spare capacity of the buffer. Will never be less than sizeInBytes.
Declaration
public long capacityInBytes { get; }
Property Value
Type | Description |
---|---|
Int64 | Size of allocated memory in bytes. |
Remarks
A buffer's capacity determines how much event data can be written to the buffer before it has to be reallocated.
data
The raw underlying memory buffer.
Declaration
public NativeArray<byte> data { get; }
Property Value
Type | Description |
---|---|
NativeArray<Byte> | Underlying buffer of unmanaged memory. |
eventCount
Total number of events in the buffer.
Declaration
public int eventCount { get; }
Property Value
Type | Description |
---|---|
Int32 | Number of events currently in the buffer. |
sizeInBytes
Size of the used portion of the buffer in bytes. Use capacityInBytes to get the total allocated size.
Declaration
public long sizeInBytes { get; }
Property Value
Type | Description |
---|---|
Int64 | Used size of buffer in bytes. |
Remarks
If the size is not known, returns BufferSizeUnknown.
Note that the size does not usually correspond to eventCount times sizeof(InputEvent)
.
as InputEvent instances are variable in size.
Methods
AllocateEvent(Int32, Int32)
Declaration
public InputEvent*AllocateEvent(int sizeInBytes, int capacityIncrementInBytes = 2048)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sizeInBytes | |
Int32 | capacityIncrementInBytes |
Returns
Type | Description |
---|---|
InputEvent* |
AppendEvent(InputEvent*, Int32)
Append a new event to the end of the buffer.
Declaration
public void AppendEvent(InputEvent*eventPtr, int capacityIncrementInBytes = 2048)
Parameters
Type | Name | Description |
---|---|---|
InputEvent* | eventPtr | |
Int32 | capacityIncrementInBytes |
Remarks
If the buffer's current capacityInBytes is smaller than the sizeInBytes of the given eventPtr
,
Exceptions
Type | Condition |
---|---|
ArgumentNullException | |
ArgumentException |
Clone()
Declaration
public InputEventBuffer Clone()
Returns
Type | Description |
---|---|
InputEventBuffer |
Contains(InputEvent*)
Whether the given event pointer refers to data within the event buffer.
Declaration
public bool Contains(InputEvent*eventPtr)
Parameters
Type | Name | Description |
---|---|---|
InputEvent* | eventPtr |
Returns
Type | Description |
---|---|
Boolean |
Remarks
Note that this method does NOT check whether the given pointer points to an actual event in the buffer. It solely performs a pointer out-of-bounds check.
Also note that if the size of the memory buffer is unknown (BufferSizeUnknown, only a lower-bounds check is performed.
Dispose()
Declaration
public void Dispose()
Implements
GetEnumerator()
Declaration
public IEnumerator<InputEventPtr> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<InputEventPtr> |
Implements
Reset()
Declaration
public void Reset()
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |
Implements
ICloneable.Clone()
Declaration
object ICloneable.Clone()
Returns
Type | Description |
---|---|
Object |