<!--
{
  "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/CMBlockBufferCreateContiguous(allocator:sourceBuffer:blockAllocator:customBlockSource:offsetToData:dataLength:flags:blockBufferOut:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Media"
    ],
    "preciseIdentifier" : "c:@F@CMBlockBufferCreateContiguous"
  },
  "title" : "CMBlockBufferCreateContiguous(allocator:sourceBuffer:blockAllocator:customBlockSource:offsetToData:dataLength:flags:blockBufferOut:)"
}
-->

# CMBlockBufferCreateContiguous(allocator:sourceBuffer:blockAllocator:customBlockSource:offsetToData:dataLength:flags:blockBufferOut:)

Creates a block buffer that contains a contiguous copy of, or reference to, the data specified by the parameters.

```
func CMBlockBufferCreateContiguous(allocator structureAllocator: CFAllocator?, sourceBuffer: CMBlockBuffer, blockAllocator: CFAllocator?, customBlockSource: UnsafePointer<CMBlockBufferCustomBlockSource>?, 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.

`sourceBuffer`

`CMBlockBuffer` from which data will be copied or referenced. Must not be `NULL` or empty.

`blockAllocator`

Allocator to be used for allocating the memory block if a contiguous copy of the data is to be made. Passing `NULL` will cause the default allocator (as set at the time of the call) to be used.

`customBlockSource`

If non-`NULL`, it will be used for the allocation and freeing of the memory block (the `blockAllocator` parameter is ignored). If provided, and the parameter `kCMBlockBufferAlwaysCopyDataFlag` is set, `customBlockSource’s`  `AllocateBlock()` routine must be non-`NULL`. Allocate will be called once, if successful, when the memory block is allocated. [`FreeBlock`](/documentation/CoreMedia/CMBlockBufferCustomBlockSource/FreeBlock) will be called once when the `CMBlockBuffer` is disposed.

`offsetToData`

Offset within the source `CMBlockBuffer` at which the new `CMBlockBuffer` should obtain data.

`dataLength`

Number of relevant data bytes, starting at `offsetToData`, within the source `CMBlockBuffer`. If zero, the target buffer’s total available `dataLength` (starting at offsetToData) will be referenced.

`flags`

Feature and control flags.

`blockBufferOut`

Receives newly-created `CMBlockBuffer` object with a retain count of 1. Must not be  `NULL`.

## Return Value

Returns `kCMBlockBufferNoErr` if successful.

## Discussion

Produces a `CMBlockBuffer` containing a contiguous copy of or reference to the data specified by the parameters. The resulting new `CMBlockBuffer` may contain an allocated copy of the data, or may contain a contiguous `CMBlockBuffer` reference. If the `kCMBlockBufferAlwaysCopyDataFlag` is set in the flags parameter, the resulting `CMBlockBuffer` will contain an allocated copy of the data rather than a reference to the `SourceBuffer`.

---

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)