---
title: "setBytes(_:length:index:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlcomputecommandencoder/setbytes(_:length:index:)"
---

# setBytes(_:length:index:)

Copies data directly to the GPU to populate an entry in the buffer argument table.

## Declaration

```swift
func setBytes(_ bytes: UnsafeRawPointer, length: Int, index: Int)
```

## Parameters

- `bytes`: A pointer to where the data to copy starts.
- `length`: The number of bytes to copy.
- `index`: The index the data binds to in the argument table.

## Discussion

Discussion important: This method only works for data smaller than 4 kilobytes that doesn’t persist. Create an MTLBuffer instance if your data exceeds 4 KB, needs to persist on the GPU, or you access results on the CPU. This method allows Metal to copy data efficiently onto the GPU without the need for your own buffer. Binding data directly can improve performance, especially when making many small allocations.

## See Also

### Binding raw bytes

- [setBytes(_:length:attributeStride:index:)](metal/mtlcomputecommandencoder/setbytes(_:length:attributestride:index:).md)
