# NativeBitArray

> An arbitrarily-sized array of bits.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule
* **Implements:** [INativeDisposable](/engine/6000.7/script-reference/unity/collections/inativedisposable.md), [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

```csharp
public struct NativeBitArray : 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.

## Static Fields

| Value                                                                                          | Description                                                     |
| ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| [MaxCapacity](/engine/6000.7/script-reference/unity/collections/nativebitarray/maxcapacity.md) | The maximum number of elements this type of container can hold. |

## Constructors

| Constructor                                                                                                                                                                                      | Description                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------ |
| [NativeBitArray(System.Int32,Unity.Collections.AllocatorManager.AllocatorHandle,Unity.Collections.NativeArrayOptions)](/engine/6000.7/script-reference/unity/collections/nativebitarray/ctor.md) | Initializes and returns an instance of NativeBitArray. |

## Properties

| Property                                                                                   | Description                                                      |
| ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------- |
| [Capacity](/engine/6000.7/script-reference/unity/collections/nativebitarray/capacity.md)   | Returns the capacity number of bits.                             |
| [IsCreated](/engine/6000.7/script-reference/unity/collections/nativebitarray/iscreated.md) | Whether this array has been allocated (and not yet deallocated). |
| [IsEmpty](/engine/6000.7/script-reference/unity/collections/nativebitarray/isempty.md)     | Whether the container is empty.                                  |
| [Length](/engine/6000.7/script-reference/unity/collections/nativebitarray/length.md)       | Returns the number of bits.                                      |

## Methods

| Method                                                                                             | Description                                                                                                                                                                             |
| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AsNativeArray](/engine/6000.7/script-reference/unity/collections/nativebitarray/asnativearray.md) | Returns a native array that aliases the content of this array.                                                                                                                          |
| [AsReadOnly](/engine/6000.7/script-reference/unity/collections/nativebitarray/asreadonly.md)       | Returns a readonly version of this NativeBitArray instance.                                                                                                                             |
| [Clear](/engine/6000.7/script-reference/unity/collections/nativebitarray/clear.md)                 | Sets all the bits to 0.                                                                                                                                                                 |
| [Copy](/engine/6000.7/script-reference/unity/collections/nativebitarray/copy.md)                   | Copies a range of bits from this array to another range in this array.                                                                                                                  |
| [CountBits](/engine/6000.7/script-reference/unity/collections/nativebitarray/countbits.md)         | Returns the number of bits in a range that are 1.                                                                                                                                       |
| [Dispose](/engine/6000.7/script-reference/unity/collections/nativebitarray/dispose.md)             | Releases all resources (memory and safety handles).                                                                                                                                     |
| [Find](/engine/6000.7/script-reference/unity/collections/nativebitarray/find.md)                   | Find 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. |
| [GetBits](/engine/6000.7/script-reference/unity/collections/nativebitarray/getbits.md)             | Returns a ulong which has bits copied from this array.                                                                                                                                  |
| [IsSet](/engine/6000.7/script-reference/unity/collections/nativebitarray/isset.md)                 | Returns true if the bit at an index is 1.                                                                                                                                               |
| [Resize](/engine/6000.7/script-reference/unity/collections/nativebitarray/resize.md)               | Sets the length, expanding the capacity if necessary.                                                                                                                                   |
| [Set](/engine/6000.7/script-reference/unity/collections/nativebitarray/set.md)                     | Sets the bit at an index to 0 or 1.                                                                                                                                                     |
| [SetBits](/engine/6000.7/script-reference/unity/collections/nativebitarray/setbits.md)             | Sets a range of bits to 0 or 1.                                                                                                                                                         |
| [SetCapacity](/engine/6000.7/script-reference/unity/collections/nativebitarray/setcapacity.md)     | Sets the capacity.                                                                                                                                                                      |
| [TestAll](/engine/6000.7/script-reference/unity/collections/nativebitarray/testall.md)             | Returns true if all of the bits in a range are 1.                                                                                                                                       |
| [TestAny](/engine/6000.7/script-reference/unity/collections/nativebitarray/testany.md)             | Returns true if at least one of the bits in a range is 1.                                                                                                                               |
| [TestNone](/engine/6000.7/script-reference/unity/collections/nativebitarray/testnone.md)           | Returns true if none of the bits in a range are 1 ("i.e." all bits in the range are 0).                                                                                                 |
| [TrimExcess](/engine/6000.7/script-reference/unity/collections/nativebitarray/trimexcess.md)       | Sets the capacity to match what it would be if it had been originally initialized with all its entries.                                                                                 |

## Structs

| Struct                                                                                                  | Description                                                                                   |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| [NativeBitArray.ReadOnly](/engine/6000.7/script-reference/unity/collections/nativebitarray/readonly.md) | A read-only alias for the value of a UnsafeBitArray. Does not have its own allocated storage. |
