docs.unity3d.com
    目次を表示する/隠す

    Struct UnsafeAppendBuffer

    An unmanaged, untyped, heterogeneous buffer.

    Namespace: Unity.Collections.LowLevel.Unsafe
    Syntax
    public struct UnsafeAppendBuffer : INativeDisposable, IDisposable
    Remarks

    The values written to an individual append buffer can be of different types.

    Constructors

    UnsafeAppendBuffer(Int32, Int32, AllocatorManager.AllocatorHandle)

    Initializes and returns an instance of UnsafeAppendBuffer.

    Declaration
    public UnsafeAppendBuffer(int initialCapacity, int alignment, AllocatorManager.AllocatorHandle allocator)
    Parameters
    Type Name Description
    Int32 initialCapacity

    The initial allocation size in bytes of the internal buffer.

    Int32 alignment

    The byte alignment of the allocation. Must be a non-zero power of 2.

    AllocatorManager.AllocatorHandle allocator

    The allocator to use.

    UnsafeAppendBuffer(Void*, Int32)

    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.

    Int32 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
    Int32

    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
    Int32

    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
    Int32

    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 readonly bool IsCreated { get; }
    Property Value
    Type Description
    Boolean

    True if this append buffer has been allocated (and not yet deallocated).

    IsEmpty

    Whether the append buffer is empty.

    Declaration
    public readonly bool IsEmpty { get; }
    Property Value
    Type Description
    Boolean

    True if the append buffer is empty.

    Methods

    Add(Void*, Int32)

    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.

    Int32 structSize

    The size in bytes of the value to be appended.

    Remarks

    The value itself is stored, not the pointer.

    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.

    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.

    AddArray<T>(Void*, Int32)

    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.

    Int32 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.

    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.

    Implements
    INativeDisposable.Dispose(JobHandle)

    Pop(Void*, Int32)

    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.

    Int32 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(Int32)

    Sets the length in bytes.

    Declaration
    public void ResizeUninitialized(int length)
    Parameters
    Type Name Description
    Int32 length

    The new length.

    Remarks

    If the new length exceeds the capacity, capacity is expanded to the new length.

    SetCapacity(Int32)

    Sets the size in bytes of the internal buffer.

    Declaration
    public void SetCapacity(int capacity)
    Parameters
    Type Name Description
    Int32 capacity

    A new capacity in bytes.

    Remarks

    Does nothing if the new capacity is less than or equal to the current capacity.

    Extension Methods

    Extensions.AddNBC(ref UnsafeAppendBuffer, String)
    Extensions.ToBytesNBC(ref UnsafeAppendBuffer)
    トップに戻る
    Copyright © 2023 Unity Technologies — 商標と利用規約
    • 法律関連
    • プライバシーポリシー
    • クッキー
    • 私の個人情報を販売または共有しない
    • Your Privacy Choices (Cookie Settings)