---
title: withCapacity
framework: driverkit
role: symbol
role_heading: Static Method
path: driverkit/osarray/withcapacity
---

# withCapacity

Allocates an OSArray object with preallocated capacity.

## Declaration

```occ
static OSArrayPtr withCapacity(uint32_t capacity);
```

## Parameters

- `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

- [withArray](driverkit/osarray/witharray.md)
- [withObjects](driverkit/osarray/withobjects.md)
- [OSArrayCreate](driverkit/osarraycreate.md)
- [merge](driverkit/osarray/merge.md)
- [free](driverkit/osarray/free.md)
- [flushCollection](driverkit/osarray/flushcollection.md)
