Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


UnsafeBitArray

An arbitrarily-sized array of bits.
Read time 2 minutesLast updated 12 days ago

Definition

public struct UnsafeBitArray : INativeDisposable, IDisposable

Remarks

The number of allocated bytes is always a multiple of 8. For example, a 65-bit array could fit in 9 bytes, but its allocation is actually 16 bytes.

Fields

Value

Description

AllocatorThe allocator to use.
CapacityThe capacity number of bits.
LengthThe number of bits.
PtrPointer to the data.

Static Fields

Value

Description

MaxCapacityThe maximum number of elements this type of container can hold.

Constructors

Constructor

Description

UnsafeBitArray(System.Int32,Unity.Collections.AllocatorManager.AllocatorHandle,Unity.Collections.NativeArrayOptions)Initializes and returns an instance of UnsafeBitArray.
UnsafeBitArray(System.Void*,System.Int32,Unity.Collections.AllocatorManager.AllocatorHandle)Initializes and returns an instance of UnsafeBitArray which aliases an existing buffer.

Properties

Property

Description

IsCreatedWhether this array has been allocated (and not yet deallocated).
IsEmptyWhether the container is empty.

Methods

Method

Description

AsReadOnlyReturns a readonly version of this UnsafeBitArray instance.
ClearSets all the bits to 0.
CopyCopies a range of bits from this array to another range in this array.
CountBitsReturns the number of bits in a range that are 1.
DisposeReleases all resources (memory and safety handles).
FindFind a sequence of N contiguous 0 bits in a bit array. To achieve higher performance, it is not guaranteed that the found index is necessarily the first occurrence of such a sequence.
GetBitsReturns a ulong which has bits copied from this array.
IsSetReturns true if the bit at an index is 1.
ResizeSets the length, expanding the capacity if necessary.
SetSets the bit at an index to 0 or 1.
SetBitsSets a range of bits to 0 or 1.
SetCapacitySets the capacity.
TestAllReturns true if all of the bits in a range are 1.
TestAnyReturns true if at least one of the bits in a range is 1.
TestNoneReturns true if none of the bits in a range are 1 ("i.e." all bits in the range are 0).
TrimExcessSets the capacity to match what it would be if it had been originally initialized with all its entries.

Static Methods

Method

Description

SetSets the bit at an index to 0 or 1.

Structs

Struct

Description

UnsafeBitArray.ReadOnlyA read-only alias for the value of a UnsafeBitArray. Does not have its own allocated storage.