---
title: withArray
framework: Kernel
role: symbol
role_heading: Type Method
platforms: [driverkit 19.0+, macOS 10.15+]
path: kernel/osarray/3180823-witharray
---

# withArray

Allocates an OSArray object with given members and preallocated capacity.

## Declaration

```occ
static OSArrayPtr withArray(const OSArray *array, uint32_t capacity);
```

```occ
static OSPtr<OSArray> withArray(const OSArray *array, unsigned int capacity);
```

## Parameters

- `array`: Array object containing members for the new array.
- `capacity`: Count of allocated capacity for members in array.

## Return Value

Return Value NULL on failure, otherwise the allocated OSArray with reference count 1 to be released by the caller.

## See Also

### Creating an Array

- [withCapacity](kernel/osarray/3180824-withcapacity.md)
- [withObjects](kernel/osarray/3180825-withobjects.md)
- [merge](kernel/osarray/3180819-merge.md)
- [free](kernel/osarray/3180811-free.md)
- [flushCollection](kernel/osarray/3180810-flushcollection.md)
