<!--
{
  "documentType" : "article",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/cmblockbuffer-api",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "CMBlockBuffer"
}
-->

# CMBlockBuffer

An object the system uses to move blocks of memory through a processing system.

## Discussion

A block buffer is a `CFType` object that represents a contiguous range of data offsets (from zero to [`CMBlockBufferGetDataLength(_:)`](/documentation/CoreMedia/CMBlockBufferGetDataLength(_:))) across a possibly noncontiguous memory region. The memory region contains memory blocks and buffer references. The buffer references can in turn refer to additional regions. `CMBlockBuffer` uses [`CMAttachmentBearerProtocol`](/documentation/CoreMedia/CMAttachmentBearerProtocol) to propagate attachments.

## Topics

### Creating a Block Buffer

[`func CMBlockBufferCreateEmpty(allocator: CFAllocator?, capacity: UInt32, flags: CMBlockBufferFlags, blockBufferOut: UnsafeMutablePointer<CMBlockBuffer?>) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferCreateEmpty(allocator:capacity:flags:blockBufferOut:))

Creates an empty block buffer.

[`func CMBlockBufferCreateWithMemoryBlock(allocator: CFAllocator?, memoryBlock: UnsafeMutableRawPointer?, blockLength: Int, blockAllocator: CFAllocator?, customBlockSource: UnsafePointer<CMBlockBufferCustomBlockSource>?, offsetToData: Int, dataLength: Int, flags: CMBlockBufferFlags, blockBufferOut: UnsafeMutablePointer<CMBlockBuffer?>) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferCreateWithMemoryBlock(allocator:memoryBlock:blockLength:blockAllocator:customBlockSource:offsetToData:dataLength:flags:blockBufferOut:))

Creates a block buffer that’s backed by a memory block.

[`func CMBlockBufferCreateWithBufferReference(allocator: CFAllocator?, referenceBuffer: CMBlockBuffer, offsetToData: Int, dataLength: Int, flags: CMBlockBufferFlags, blockBufferOut: UnsafeMutablePointer<CMBlockBuffer?>) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferCreateWithBufferReference(allocator:referenceBuffer:offsetToData:dataLength:flags:blockBufferOut:))

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

[`func CMBlockBufferCreateContiguous(allocator: CFAllocator?, sourceBuffer: CMBlockBuffer, blockAllocator: CFAllocator?, customBlockSource: UnsafePointer<CMBlockBufferCustomBlockSource>?, offsetToData: Int, dataLength: Int, flags: CMBlockBufferFlags, blockBufferOut: UnsafeMutablePointer<CMBlockBuffer?>) -> OSStatus`](/documentation/CoreMedia/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.

[`typealias CMBlockBufferFlags`](/documentation/CoreMedia/CMBlockBufferFlags)

A type for flags that control behaviors and features of block buffer APIs.

[Block Buffer Flags](/documentation/CoreMedia/block-buffer-flags)

An enumeration of flags that control behaviors and features of block buffer APIs.

[`struct CMBlockBufferCustomBlockSource`](/documentation/CoreMedia/CMBlockBufferCustomBlockSource)

A structure to support custom memory allocation and deallocation for a block used in a block buffer.

[Custom Block Source Version](/documentation/CoreMedia/custom-block-source-version)

A custom block source version identifier.

### Modifying a Block Buffer

[`func CMBlockBufferAppendMemoryBlock(CMBlockBuffer, memoryBlock: UnsafeMutableRawPointer?, length: Int, blockAllocator: CFAllocator?, customBlockSource: UnsafePointer<CMBlockBufferCustomBlockSource>?, offsetToData: Int, dataLength: Int, flags: CMBlockBufferFlags) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferAppendMemoryBlock(_:memoryBlock:length:blockAllocator:customBlockSource:offsetToData:dataLength:flags:))

Adds a memory block to an existing block buffer.

[`func CMBlockBufferAppendBufferReference(CMBlockBuffer, targetBBuf: CMBlockBuffer, offsetToData: Int, dataLength: Int, flags: CMBlockBufferFlags) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferAppendBufferReference(_:targetBBuf:offsetToData:dataLength:flags:))

Adds a reference to an existing block buffer.

[`func CMBlockBufferAssureBlockMemory(CMBlockBuffer) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferAssureBlockMemory(_:))

Assures that the system allocates memory for all memory blocks in a block buffer.

[`func CMBlockBufferAccessDataBytes(CMBlockBuffer, atOffset: Int, length: Int, temporaryBlock: UnsafeMutableRawPointer, returnedPointerOut: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferAccessDataBytes(_:atOffset:length:temporaryBlock:returnedPointerOut:))

Accesses potentially noncontiguous data in a block buffer.

[`func CMBlockBufferCopyDataBytes(CMBlockBuffer, atOffset: Int, dataLength: Int, destination: UnsafeMutableRawPointer) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferCopyDataBytes(_:atOffset:dataLength:destination:))

Copies bytes from a block buffer into a provided memory area.

[`func CMBlockBufferReplaceDataBytes(with: UnsafeRawPointer, blockBuffer: CMBlockBuffer, offsetIntoDestination: Int, dataLength: Int) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferReplaceDataBytes(with:blockBuffer:offsetIntoDestination:dataLength:))

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

[`func CMBlockBufferFillDataBytes(with: CChar, blockBuffer: CMBlockBuffer, offsetIntoDestination: Int, dataLength: Int) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferFillDataBytes(with:blockBuffer:offsetIntoDestination:dataLength:))

Fills the destination buffer with the specified data byte.

### Inspecting a Block Buffer

[`func CMBlockBufferGetDataPointer(CMBlockBuffer, atOffset: Int, lengthAtOffsetOut: UnsafeMutablePointer<Int>?, totalLengthOut: UnsafeMutablePointer<Int>?, dataPointerOut: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?) -> OSStatus`](/documentation/CoreMedia/CMBlockBufferGetDataPointer(_:atOffset:lengthAtOffsetOut:totalLengthOut:dataPointerOut:))

Gains access to the data represented by a block buffer.

[`func CMBlockBufferGetDataLength(CMBlockBuffer) -> Int`](/documentation/CoreMedia/CMBlockBufferGetDataLength(_:))

Returns the total length of data that’s accessible by a block buffer.

[`func CMBlockBufferIsRangeContiguous(CMBlockBuffer, atOffset: Int, length: Int) -> Bool`](/documentation/CoreMedia/CMBlockBufferIsRangeContiguous(_:atOffset:length:))

Returns a Boolean value that indicates whether the specified range within a block buffer is contiguous.

[`func CMBlockBufferIsEmpty(CMBlockBuffer) -> Bool`](/documentation/CoreMedia/CMBlockBufferIsEmpty(_:))

Returns a Boolean value that indicates whether the buffer is empty.

### Accessing the Type Identifier

[`func CMBlockBufferGetTypeID() -> CFTypeID`](/documentation/CoreMedia/CMBlockBufferGetTypeID())

Returns the type identifier for block buffer objects.

### Data Types

[`class CMBlockBuffer`](/documentation/CoreMedia/CMBlockBuffer)

A reference to a block buffer instance.

[`protocol CMBlockBufferProtocol`](/documentation/CoreMedia/CMBlockBufferProtocol)

A protocol for objects that operate on a range of a block buffer.

### Errors

[Block Buffer Error Codes](/documentation/CoreMedia/block-buffer-error-codes)

Error codes that framework operations produce.



---

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)