---
title: "init(capacity:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/data/init(capacity:)"
---

# init(capacity:)

Creates an empty data buffer of a specified size.

## Declaration

```swift
init(capacity: Int)
```

## Parameters

- `capacity`: The size of the data.

## Discussion

Discussion This initializer doesn’t necessarily allocate the requested memory right away. Data allocates additional memory as needed, so capacity simply establishes the initial capacity. When it does allocate the initial memory, though, it allocates the specified amount. This method sets the count of the data to 0. If the capacity specified in capacity is greater than four memory pages in size, this may round the amount of requested memory up to the nearest full page.

## See Also

### Creating Empty Data

- [init()](foundation/data/init().md)
- [init(count:)](foundation/data/init(count:).md)
- [resetBytes(in:)](foundation/data/resetbytes(in:).md)
