<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UnsafeMutableRawPointer/allocate(byteCount:alignment:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sv8allocate9byteCount9alignmentSvSi_SitFZ"
  },
  "title" : "allocate(byteCount:alignment:)"
}
-->

# allocate(byteCount:alignment:)

Allocates uninitialized memory with the specified size and alignment.

```
static func allocate(byteCount: Int, alignment: Int) -> UnsafeMutableRawPointer
```

## Parameters

`byteCount`

The number of bytes to allocate. `byteCount` must not be
negative.

`alignment`

The alignment of the new region of allocated memory, in
bytes. `alignment` must be a whole power of 2.

## Return Value

A pointer to a newly allocated region of memory. The memory is
allocated, but not initialized.

## Discussion

You are in charge of managing the allocated memory. Be sure to deallocate
any memory that you manually allocate.

The allocated memory is not bound to any specific type and must be bound
before performing any typed operations. If you are using the memory for
a specific type, allocate memory using the
`UnsafeMutablePointer.allocate(capacity:)` static method instead.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)