---
title: withCapacity
framework: Kernel
role: symbol
role_heading: Type Method
platforms: [driverkit 19.0+, macOS 10.15+]
path: kernel/osarray/3180824-withcapacity
---

# withCapacity

Allocates an OSArray object with preallocated capacity.

## Declaration

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

```occ
static OSPtr<OSArray> withCapacity(unsigned int 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](kernel/osarray/3180823-witharray.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)
