<!--
{
  "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/UnsafeMutableRawBufferPointer/bindMemory(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sw10bindMemory2toSryxGxm_tRi_zlF"
  },
  "title" : "bindMemory(to:)"
}
-->

# bindMemory(to:)

Binds this buffer’s memory to the specified type and returns a typed
buffer of the bound memory.

```
@discardableResult func bindMemory<T>(to type: T.Type) -> UnsafeMutableBufferPointer<T> where T : ~Copyable
```

## Parameters

`type`

The type `T` to bind the memory to.

## Return Value

A typed buffer of the newly bound memory. The memory in this
region is bound to `T`, but has not been modified in any other way.
The typed buffer references `self.count / MemoryLayout<T>.stride`
instances of `T`.

## Discussion

Use the `bindMemory(to:)` method to bind the memory referenced
by this buffer to the type `T`. The memory must be uninitialized or
initialized to a type that is layout compatible with `T`. If the memory
is uninitialized, it is still uninitialized after being bound to `T`.

> Warning: A memory location may only be bound to one type at a time. The
> behavior of accessing memory as a type unrelated to its bound type is
> undefined.

---

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)