Struct UnsafeAppendBuffer
An unmanaged, untyped, buffer, without any thread safety check features.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafeAppendBuffer : INativeDisposable, IDisposable
Constructors
UnsafeAppendBuffer(Int32, Int32, Allocator)
Constructs a new container with the specified initial capacity and type of memory allocation.
Declaration
public UnsafeAppendBuffer(int initialCapacity, int alignment, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Int32 | initialCapacity | The initial capacity of the list. If the list grows larger than its capacity, the internal array is copied to a new, larger array. |
Int32 | alignment | |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
UnsafeAppendBuffer(Void*, Int32)
Constructs container as view into memory.
Declaration
public UnsafeAppendBuffer(void *ptr, int length)
Parameters
Type | Name | Description |
---|---|---|
Void* | ptr | Pointer to data. |
Int32 | length | Lenght of data in bytes. |
Remarks
Internal capacity will be set to lenght, but internal length will be set to zero.
Fields
Alignment
Declaration
public readonly int Alignment
Field Value
Type | Description |
---|---|
Int32 |
Allocator
Declaration
public Allocator Allocator
Field Value
Type | Description |
---|---|
Allocator |
Capacity
Declaration
public int Capacity
Field Value
Type | Description |
---|---|
Int32 |
Length
Declaration
public int Length
Field Value
Type | Description |
---|---|
Int32 |
Ptr
Declaration
public byte *Ptr
Field Value
Type | Description |
---|---|
Byte* |
Properties
IsCreated
Reports whether memory for the container is allocated.
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this container object's internal storage has been allocated. |
Remarks
Note that the container storage is not created if you use the default constructor. You must specify at least an allocation type to construct a usable container.
Warning: the IsCreated
property can't be used to determine whether a copy of a container is still valid.
If you dispose any copy of the container, the container storage is deallocated. However, the properties of
the other copies of the container (including the original) are not updated. As a result the IsCreated
property
of the copies still return true
even though the container storage has been deallocated.
IsEmpty
Reports whether the container is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
Add(String)
Adds string into the container.
Declaration
public void Add(string value)
Parameters
Type | Name | Description |
---|---|---|
String | value | String to copy to container. |
Add(Void*, Int32)
Adds the element to this container.
Declaration
public void Add(void *ptr, int structSize)
Parameters
Type | Name | Description |
---|---|---|
Void* | ptr | A pointer to copy into the container. |
Int32 | structSize | Structure size in bytes. |
Add<T>(T)
Adds an element to the container.
Declaration
public void Add<T>(T value)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | The struct to be added at the end of the container. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements. |
Add<T>(NativeArray<T>)
Adds elements from a NativeArray to this container.
Declaration
public void Add<T>(NativeArray<T> value)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | Other container to copy elements from. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements. |
AddArray<T>(Void*, Int32)
Adds the elements to this container.
Declaration
public void AddArray<T>(void *ptr, int length)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
Void* | ptr | A pointer to copy into the container. |
Int32 | length | The number of elements to add to the container. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements. |
AsReader()
Returns buffer reader instance.
Declaration
public UnsafeAppendBuffer.Reader AsReader()
Returns
Type | Description |
---|---|
UnsafeAppendBuffer.Reader | Returns buffer reader instance. |
Dispose()
Disposes of this container and deallocates its memory immediately.
Declaration
public void Dispose()
Dispose(JobHandle)
Safely disposes of this container and deallocates its memory when the jobs that use it have completed.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | The job handle or handles for any scheduled jobs that use this container. |
Returns
Type | Description |
---|---|
JobHandle | A new job handle containing the prior handles as well as the handle for the job that deletes the container. |
Implements
Remarks
You can call this function dispose of the container immediately after scheduling the job. Pass
the JobHandle returned by
the Job.Schedule
method using the jobHandle
parameter so the job scheduler can dispose the container after all jobs
using it have run.
Pop(Void*, Int32)
Retrieve and remove element from the end of buffer.
Declaration
public void Pop(void *ptr, int structSize)
Parameters
Type | Name | Description |
---|---|---|
Void* | ptr | |
Int32 | structSize |
Pop<T>()
Retrieve and remove element from the end of buffer.
Declaration
public T Pop<T>()
where T : struct
Returns
Type | Description |
---|---|
T | Returns value. |
Type Parameters
Name | Description |
---|---|
T | Source type of elements. |
Reset()
Clears the container.
Declaration
public void Reset()
Remarks
The container capacity remains unchanged.
ResizeUninitialized(Int32)
Changes the container length, resizing if necessary, without initializing memory.
Declaration
public void ResizeUninitialized(int length)
Parameters
Type | Name | Description |
---|---|---|
Int32 | length | The new length of the container. |
SetCapacity(Int32)
Set the number of items that can fit in the container.
Declaration
public void SetCapacity(int capacity)
Parameters
Type | Name | Description |
---|---|---|
Int32 | capacity | The number of items that the container can hold before it resizes its internal storage. |
ToBytes()
Copy contents of the container into byte array.
Declaration
public byte[] ToBytes()
Returns
Type | Description |
---|---|
Byte[] | Array of bytes. |