Struct UnsafeAppendBuffer
An unmanaged, untyped, heterogeneous buffer.
Implements
Namespace: Unity.Collections.LowLevel.Unsafe
Assembly: Unity.Collections.dll
Syntax
public struct UnsafeAppendBuffer : INativeDisposable
Remarks
The values written to an individual append buffer can be of different types.
Constructors
UnsafeAppendBuffer(int, int, AllocatorHandle)
Initializes and returns an instance of UnsafeAppendBuffer.
Declaration
public UnsafeAppendBuffer(int initialCapacity, int alignment, AllocatorManager.AllocatorHandle allocator)
Parameters
Type | Name | Description |
---|---|---|
int | initialCapacity | The initial allocation size in bytes of the internal buffer. |
int | alignment | The byte alignment of the allocation. Must be a non-zero power of 2. |
AllocatorManager.AllocatorHandle | allocator | The allocator to use. |
UnsafeAppendBuffer(void*, int)
Initializes and returns an instance of UnsafeAppendBuffer that aliases an existing buffer.
Declaration
public UnsafeAppendBuffer(void* ptr, int length)
Parameters
Type | Name | Description |
---|---|---|
void* | ptr | The buffer to alias. |
int | length | The length in bytes of the buffer. |
Remarks
The capacity will be set to length
, and Length will be set to 0.
Fields
Alignment
The byte alignment used when allocating the internal buffer.
Declaration
public readonly int Alignment
Field Value
Type | Description |
---|---|
int | The byte alignment used when allocating the internal buffer. Is always a non-zero power of 2. |
Allocator
The allocator used to create the internal buffer.
Declaration
public AllocatorManager.AllocatorHandle Allocator
Field Value
Type | Description |
---|---|
AllocatorManager.AllocatorHandle | The allocator used to create the internal buffer. |
Capacity
The size in bytes of the internal buffer.
Declaration
public int Capacity
Field Value
Type | Description |
---|---|
int | The size in bytes of the internal buffer. |
Length
The size in bytes of the currently-used portion of the internal buffer.
Declaration
public int Length
Field Value
Type | Description |
---|---|
int | The size in bytes of the currently-used portion of the internal buffer. |
Ptr
The internal buffer where the content is stored.
Declaration
[NativeDisableUnsafePtrRestriction]
public byte* Ptr
Field Value
Type | Description |
---|---|
byte* | The internal buffer where the content is stored. |
Properties
IsCreated
Whether this append buffer has been allocated (and not yet deallocated).
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
bool | True if this append buffer has been allocated (and not yet deallocated). |
IsEmpty
Whether the append buffer is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool | True if the append buffer is empty. |
Methods
Add(void*, int)
Appends an element to the end of this append buffer.
Declaration
public void Add(void* ptr, int structSize)
Parameters
Type | Name | Description |
---|---|---|
void* | ptr | A pointer to the value to be appended. |
int | structSize | The size in bytes of the value to be appended. |
Remarks
The value itself is stored, not the pointer.
AddArray<T>(void*, int)
Appends the elements of a buffer to the end of this append buffer.
Declaration
public void AddArray<T>(void* ptr, int length) where T : struct
Parameters
Type | Name | Description |
---|---|---|
void* | ptr | A pointer to the buffer whose values will be appended. |
int | length | The number of elements to append. |
Type Parameters
Name | Description |
---|---|
T | The type of the buffer's elements. |
Remarks
The values themselves are stored, not their pointers.
Add<T>(NativeArray<T>)
Appends all elements of an array to the end of this append buffer.
Declaration
public void Add<T>(NativeArray<T> value) where T : struct
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | The array whose elements will all be appended. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Add<T>(T)
Appends an element to the end of this append buffer.
Declaration
public void Add<T>(T value) where T : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be appended. |
Type Parameters
Name | Description |
---|---|
T | The type of the element. |
AsReader()
Returns a reader for this append buffer.
Declaration
public UnsafeAppendBuffer.Reader AsReader()
Returns
Type | Description |
---|---|
UnsafeAppendBuffer.Reader | A reader for the append buffer. |
Dispose()
Releases all resources (memory and safety handles).
Declaration
public void Dispose()
Dispose(JobHandle)
Creates and schedules a job that will dispose this append buffer.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | The handle of a job which the new job will depend upon. |
Returns
Type | Description |
---|---|
JobHandle | The handle of a new job that will dispose this append buffer. The new job depends upon inputDeps. |
Pop(void*, int)
Removes and copies the last element of this append buffer.
Declaration
public void Pop(void* ptr, int structSize)
Parameters
Type | Name | Description |
---|---|---|
void* | ptr | The location to which the removed element will be copied. |
int | structSize | The size of the element to remove and copy. |
Remarks
It is your responsibility to specify the correct structSize
. Do not pop when the append buffer is empty.
Pop<T>()
Removes and returns the last element of this append buffer.
Declaration
public T Pop<T>() where T : struct
Returns
Type | Description |
---|---|
T | The element removed from the end of this append buffer. |
Type Parameters
Name | Description |
---|---|
T | The type of the element to remove. |
Remarks
It is your responsibility to specify the correct type. Do not pop when the append buffer is empty.
Reset()
Sets the length to 0.
Declaration
public void Reset()
Remarks
Does not change the capacity.
ResizeUninitialized(int)
Sets the length in bytes.
Declaration
public void ResizeUninitialized(int length)
Parameters
Type | Name | Description |
---|---|---|
int | length | The new length. |
Remarks
If the new length exceeds the capacity, capacity is expanded to the new length.
SetCapacity(int)
Sets the size in bytes of the internal buffer.
Declaration
public void SetCapacity(int capacity)
Parameters
Type | Name | Description |
---|---|---|
int | capacity | A new capacity in bytes. |
Remarks
Does nothing if the new capacity is less than or equal to the current capacity.