Struct UnsafeBitArray
Arbitrary sized array of bits.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafeBitArray
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 = null)
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)
Constructs container as view into memory.
Declaration
public UnsafeBitArray(void *ptr, int sizeInBytes)
Parameters
Type | Name | Description |
---|---|---|
Void* | ptr | Pointer to data. |
Int32 | sizeInBytes | Size of data in bytes. Must be multiple of 8-bytes. |
Fields
Allocator
Declaration
public Allocator Allocator
Field Value
Type | Description |
---|---|
Allocator |
Length
Declaration
public int Length
Field Value
Type | Description |
---|---|
Int32 |
Ptr
Declaration
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()
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 |
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.
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. |
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. |