<!--
{
  "availability" : [
    "iOS: 8.3.0 -",
    "iPadOS: 8.3.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLComputeCommandEncoder/setBytes(_:length:index:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLComputeCommandEncoder(im)setBytes:length:atIndex:"
  },
  "title" : "setBytes(_:length:index:)"
}
-->

# setBytes(_:length:index:)

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

```
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> Important:
> This method only works for data smaller than 4 kilobytes that doesn’t persist. Create an ``doc://com.apple.metal/documentation/Metal/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.

---

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)