Struct UnsafeBitArray | Collections | 0.11.0-preview.17
docs.unity3d.com
    Show / Hide Table of Contents

    Struct UnsafeBitArray

    Arbitrary sized array of bits.

    Namespace: Unity.Collections.LowLevel.Unsafe
    Syntax
    public struct UnsafeBitArray : IDisposable

    Constructors

    UnsafeBitArray(Int32, Allocator, NativeArrayOptions)

    Constructs a new container with the specified initial capacity and type of memory allocation.

    Declaration
    public UnsafeBitArray(int numBits, Allocator allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory)
    Parameters
    Type Name Description
    Int32 numBits

    Number of bits.

    Allocator allocator

    A member of the Unity.Collections.Allocator enumeration.

    NativeArrayOptions options

    Memory should be cleared on allocation or left uninitialized.

    UnsafeBitArray(Void*, Int32, Allocator)

    Constructs container as view into memory.

    Declaration
    public UnsafeBitArray(void *ptr, int sizeInBytes, Allocator allocator = Allocator.None)
    Parameters
    Type Name Description
    Void* ptr

    Pointer to data.

    Int32 sizeInBytes

    Size of data in bytes. Must be multiple of 8-bytes.

    Allocator allocator

    A member of the Unity.Collections.Allocator enumeration.

    Fields

    Allocator

    Declaration
    public Allocator Allocator
    Field Value
    Type Description
    Allocator

    Length

    Number of bits.

    Declaration
    public int Length
    Field Value
    Type Description
    Int32

    Ptr

    Pointer to data.

    Declaration
    [NativeDisableUnsafePtrRestriction]
    public ulong *Ptr
    Field Value
    Type Description
    UInt64*

    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.

    Methods

    Clear()

    Clear all bits to 0.

    Declaration
    public void Clear()

    Copy(Int32, Int32, Int32)

    Copy block of bits from source to destination.

    Declaration
    public void Copy(int dstPos, int srcPos, int numBits)
    Parameters
    Type Name Description
    Int32 dstPos

    Destination position in bit array.

    Int32 srcPos

    Source position in bit array.

    Int32 numBits

    Number of bits to copy.

    Copy(Int32, ref UnsafeBitArray, Int32, Int32)

    Copy block of bits from source to destination.

    Declaration
    public void Copy(int dstPos, ref UnsafeBitArray srcBitArray, int srcPos, int numBits)
    Parameters
    Type Name Description
    Int32 dstPos

    Destination position in bit array.

    UnsafeBitArray srcBitArray

    Source bit array from which bits will be copied.

    Int32 srcPos

    Source position in bit array.

    Int32 numBits

    Number of bits to copy.

    CountBits(Int32, Int32)

    Calculate number of set bits.

    Declaration
    public int CountBits(int pos, int numBits = 1)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    Int32 numBits

    Number of bits to perform count.

    Returns
    Type Description
    Int32

    Number of set bits.

    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.

    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.

    GetBits(Int32, Int32)

    Returns all bits in range as ulong.

    Declaration
    public ulong GetBits(int pos, int numBits = 1)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    Int32 numBits

    Number of bits to get (must be 1-64).

    Returns
    Type Description
    UInt64

    Returns requested range of bits.

    IsSet(Int32)

    Returns true is bit at position is set.

    Declaration
    public bool IsSet(int pos)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    Returns
    Type Description
    Boolean

    Returns true if bit is set.

    Set(Int32, Boolean)

    Set single bit to desired boolean value.

    Declaration
    public void Set(int pos, bool value)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    Boolean value

    Value of bits to set.

    SetBits(Int32, Boolean, Int32)

    Set bits to desired boolean value.

    Declaration
    public void SetBits(int pos, bool value, int numBits)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    Boolean value

    Value of bits to set.

    Int32 numBits

    Number of bits to set.

    SetBits(Int32, UInt64, Int32)

    Sets bits in range as ulong.

    Declaration
    public void SetBits(int pos, ulong value, int numBits = 1)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    UInt64 value

    Value of bits to set.

    Int32 numBits

    Number of bits to set (must be 1-64).

    TestAll(Int32, Int32)

    Returns true if all of bits in range are set.

    Declaration
    public bool TestAll(int pos, int numBits = 1)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    Int32 numBits

    Number of bits to test.

    Returns
    Type Description
    Boolean

    Returns true if all bits are set.

    TestAny(Int32, Int32)

    Returns true if any of bits in range are set.

    Declaration
    public bool TestAny(int pos, int numBits = 1)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    Int32 numBits

    Number of bits to test.

    Returns
    Type Description
    Boolean

    Returns true if at least one bit is set.

    TestNone(Int32, Int32)

    Returns true if none of bits in range are set.

    Declaration
    public bool TestNone(int pos, int numBits = 1)
    Parameters
    Type Name Description
    Int32 pos

    Position in bit array.

    Int32 numBits

    Number of bits to test.

    Returns
    Type Description
    Boolean

    Returns true if none of bits are set.

    In This Article
    • Constructors
      • UnsafeBitArray(Int32, Allocator, NativeArrayOptions)
      • UnsafeBitArray(Void*, Int32, Allocator)
    • Fields
      • Allocator
      • Length
      • Ptr
    • Properties
      • IsCreated
    • Methods
      • Clear()
      • Copy(Int32, Int32, Int32)
      • Copy(Int32, ref UnsafeBitArray, Int32, Int32)
      • CountBits(Int32, Int32)
      • Dispose()
      • Dispose(JobHandle)
      • GetBits(Int32, Int32)
      • IsSet(Int32)
      • Set(Int32, Boolean)
      • SetBits(Int32, Boolean, Int32)
      • SetBits(Int32, UInt64, Int32)
      • TestAll(Int32, Int32)
      • TestAny(Int32, Int32)
      • TestNone(Int32, Int32)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023