Struct InputEventBuffer
A buffer of raw memory holding a sequence of InputEvent.
Namespace: UnityEngine.InputSystem.LowLevel
Syntax
public struct InputEventBuffer : IEnumerable<InputEventPtr>, 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, Boolean)
Construct an event buffer using the array containing InputEvents.
Declaration
public InputEventBuffer(NativeArray<byte> buffer, int eventCount, int sizeInBytes = null, bool transferNativeArrayOwnership = false)
Parameters
Type | Name | Description |
---|---|---|
NativeArray<Byte> | buffer | A native array containing |
Int32 | eventCount | The number of events in |
Int32 | sizeInBytes | Total number of bytes of event data in the .
If -1 (default), the size of the actual event data in |
Boolean | transferNativeArrayOwnership | If true, ownership of the |
InputEventBuffer(InputEvent*, Int32, Int32, Int32)
Construct an event buffer using the given memory block containing InputEvents.
Declaration
public InputEventBuffer(InputEvent*eventPtr, int eventCount, int sizeInBytes = null, int capacityInBytes = null)
Parameters
Type | Name | Description |
---|---|---|
InputEvent* | eventPtr | A buffer containing |
Int32 | eventCount | The number of events in |
Int32 | sizeInBytes | Total number of bytes of event data in the memory block pointed to by |
Int32 | capacityInBytes | The total size of the memory block allocated at |
Fields
BufferSizeUnknown
Declaration
public const long BufferSizeUnknown = null
Field Value
Type | Description |
---|---|
Int64 |
Properties
bufferPtr
Pointer to the first event in the buffer.
Declaration
public readonly 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 readonly 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 readonly 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 readonly 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 readonly 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, Allocator)
Make space for an event of sizeInBytes
bytes and return a pointer to
the memory for the event.
Declaration
public InputEvent*AllocateEvent(int sizeInBytes, int capacityIncrementInBytes = 2048, Allocator allocator = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sizeInBytes | Number of bytes to make available for the event including the event header (see InputEvent). |
Int32 | capacityIncrementInBytes | If the buffer needs to be reallocated to accommodate the event, number of bytes to grow the buffer by. |
Allocator | allocator | If the buffer needs to be reallocated to accommodate the event, the type of allocation to use. |
Returns
Type | Description |
---|---|
InputEvent* | A pointer to a block of memory in bufferPtr. Store the event data here. |
Remarks
Only sizeInBytes is initialized by this method. No other fields from the event's header are touched.
The event will be appended to the buffer after the last event currently in the buffer (if any).
AppendEvent(InputEvent*, Int32, Allocator)
Append a new event to the end of the buffer by copying the event from eventPtr
.
Declaration
public void AppendEvent(InputEvent*eventPtr, int capacityIncrementInBytes = 2048, Allocator allocator = null)
Parameters
Type | Name | Description |
---|---|---|
InputEvent* | eventPtr | Data of the event to store in the buffer. This will be copied in full as per sizeInBytes found in the event's header. |
Int32 | capacityIncrementInBytes | If the buffer needs to be reallocated to accommodate the event, number of bytes to grow the buffer by. |
Allocator | allocator | If the buffer needs to be reallocated to accommodate the event, the type of allocation to use. |
Remarks
If the buffer's current capacity (see capacityInBytes) is smaller than sizeInBytes of the given event, the buffer will be reallocated.
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()
GetEnumerator()
Declaration
public IEnumerator<InputEventPtr> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<InputEventPtr> |
Reset()
Declaration
public void Reset()