<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/CMBlockBufferReplaceDataBytes(with:blockBuffer:offsetIntoDestination:dataLength:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Media"
    ],
    "preciseIdentifier" : "c:@F@CMBlockBufferReplaceDataBytes"
  },
  "title" : "CMBlockBufferReplaceDataBytes(with:blockBuffer:offsetIntoDestination:dataLength:)"
}
-->

# CMBlockBufferReplaceDataBytes(with:blockBuffer:offsetIntoDestination:dataLength:)

Copies bytes from a given memory block into a block buffer replacing bytes in the underlying data blocks.

```
func CMBlockBufferReplaceDataBytes(with sourceBytes: UnsafeRawPointer, blockBuffer destinationBuffer: CMBlockBuffer, offsetIntoDestination: Int, dataLength: Int) -> OSStatus
```

## Parameters

`sourceBytes`

Memory block from which bytes are copied into the destination `CMBlockBuffer`.

`destinationBuffer`

`CMBlockBuffer` whose range of bytes will be replaced by the `sourceBytes`.

`offsetIntoDestination`

Offset within the destination `CMBlockBuffer` at which replacement should begin.

`dataLength`

Number of bytes to be replaced, starting at `offsetIntoDestination`, in the `destinationBuffer`.

## Return Value

Returns `kCMBlockBufferNoErr` if the replacement succeeded, returns an error otherwise.

## Discussion

This function is used to replace bytes in a `CMBlockBuffer's` memory blocks with those from a provided piece of memory. It deals with the possibility of the destination range of data being noncontiguous. `CMBlockBufferAssureBlockMemory`() is called on the given `CMBlockBuffer`. If desired range is subsequently not accessible in the `CMBlockBuffer`, an error is returned and the contents of the `CMBlockBuffer` are untouched.

---

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)