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

# withCapacity

Allocates an OSData object with preallocated capacity.

## Declaration

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

```occ
static OSPtr<OSData> withCapacity(unsigned int capacity);
```

## Parameters

- `capacity`: Number of bytes of data the object can hold.

## Return Value

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

## Discussion

Discussion Allocates an OSData object with preallocated capacity. The OSData will have zero length until data is added to it with appendBytes().

## See Also

### Creating a Data Object

- [withBytes](driverkit/osdata/withbytes.md)
- [withBytesNoCopy](driverkit/osdata/withbytesnocopy.md)
- [withData](kernel/osdata/3180886-withdata.md)
- [withData](kernel/osdata/3433845-withdata.md)
- [OSDataPtr](driverkit/osdataptr.md)
- [free](kernel/osdata/3180878-free.md)
