---
title: "CMBlockBufferReplaceDataBytes(with:blockBuffer:offsetIntoDestination:dataLength:)"
framework: coremedia
role: symbol
role_heading: Function
path: "coremedia/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.

## Declaration

```swift
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

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

## Discussion

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.

## See Also

### Modifying a Block Buffer

- [CMBlockBufferAppendMemoryBlock(_:memoryBlock:length:blockAllocator:customBlockSource:offsetToData:dataLength:flags:)](coremedia/cmblockbufferappendmemoryblock(_:memoryblock:length:blockallocator:customblocksource:offsettodata:datalength:flags:).md)
- [CMBlockBufferAppendBufferReference(_:targetBBuf:offsetToData:dataLength:flags:)](coremedia/cmblockbufferappendbufferreference(_:targetbbuf:offsettodata:datalength:flags:).md)
- [CMBlockBufferAssureBlockMemory(_:)](coremedia/cmblockbufferassureblockmemory(_:).md)
- [CMBlockBufferAccessDataBytes(_:atOffset:length:temporaryBlock:returnedPointerOut:)](coremedia/cmblockbufferaccessdatabytes(_:atoffset:length:temporaryblock:returnedpointerout:).md)
- [CMBlockBufferCopyDataBytes(_:atOffset:dataLength:destination:)](coremedia/cmblockbuffercopydatabytes(_:atoffset:datalength:destination:).md)
- [CMBlockBufferFillDataBytes(with:blockBuffer:offsetIntoDestination:dataLength:)](coremedia/cmblockbufferfilldatabytes(with:blockbuffer:offsetintodestination:datalength:).md)
