---
title: "CMBlockBufferCreateWithBufferReference(allocator:referenceBuffer:offsetToData:dataLength:flags:blockBufferOut:)"
framework: coremedia
role: symbol
role_heading: Function
path: "coremedia/cmblockbuffercreatewithbufferreference(allocator:referencebuffer:offsettodata:datalength:flags:blockbufferout:)"
---

# CMBlockBufferCreateWithBufferReference(allocator:referenceBuffer:offsetToData:dataLength:flags:blockBufferOut:)

Creates a block buffer that refers to another block buffer object.

## Declaration

```swift
func CMBlockBufferCreateWithBufferReference(allocator structureAllocator: CFAllocator?, referenceBuffer bufferReference: CMBlockBuffer, offsetToData: Int, dataLength: Int, flags: CMBlockBufferFlags, blockBufferOut: UnsafeMutablePointer<CMBlockBuffer?>) -> OSStatus
```

## Parameters

- `structureAllocator`: Allocator to use for allocating the CMBlockBuffer object. NULL will cause the default allocator to be used.
- `bufferReference`: The target CMBlockBuffer. This parameter must not be NULL. Unless the kCMBlockBufferPermitEmptyReferenceFlag is passed, it must not be empty and it must have a data length at least large enough to supply the data subset specified (i.e. offsetToData+dataLength bytes).
- `offsetToData`: Offset within the target CMBlockBuffer at which the new CMBlockBuffer should refer to data.
- `dataLength`: Number of relevant data bytes, starting at offsetToData, within the target CMBlockBuffer.
- `flags`: Feature and control flags.
- `blockBufferOut`: Receives newly-created CMBlockBuffer object with a retain count of 1. Must not be NULL.

## Return Value

Return Value Returns kCMBlockBufferNoErr if successful.

## Discussion

Discussion Creates a new CMBlockBuffer that refers to (a possibly subset portion of) another CMBlockBuffer. The returned CMBlockBuffer may be further expanded using CMBlockBufferAppendMemoryBlock(_:memoryBlock:length:blockAllocator:customBlockSource:offsetToData:dataLength:flags:) and/or CMBlockBufferAppendBufferReference(_:targetBBuf:offsetToData:dataLength:flags:).

## See Also

### Creating a Block Buffer

- [CMBlockBufferCreateEmpty(allocator:capacity:flags:blockBufferOut:)](coremedia/cmblockbuffercreateempty(allocator:capacity:flags:blockbufferout:).md)
- [CMBlockBufferCreateWithMemoryBlock(allocator:memoryBlock:blockLength:blockAllocator:customBlockSource:offsetToData:dataLength:flags:blockBufferOut:)](coremedia/cmblockbuffercreatewithmemoryblock(allocator:memoryblock:blocklength:blockallocator:customblocksource:offsettodata:datalength:flags:blockbufferout:).md)
- [CMBlockBufferCreateContiguous(allocator:sourceBuffer:blockAllocator:customBlockSource:offsetToData:dataLength:flags:blockBufferOut:)](coremedia/cmblockbuffercreatecontiguous(allocator:sourcebuffer:blockallocator:customblocksource:offsettodata:datalength:flags:blockbufferout:).md)
- [CMBlockBufferFlags](coremedia/cmblockbufferflags.md)
- [Block Buffer Flags](coremedia/block-buffer-flags.md)
- [CMBlockBufferCustomBlockSource](coremedia/cmblockbuffercustomblocksource.md)
- [Custom Block Source Version](coremedia/custom-block-source-version.md)
