---
title: "bindMemory(to:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/slice/bindmemory(to:)-4ombl"
---

# bindMemory(to:)

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

## Declaration

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

## Parameters

- `type`: The type T to bind the memory to.

## Return Value

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

Discussion Use the bindMemory(to:) method to bind the memory referenced by this buffer slice 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.
