<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/CMMutableDataBlockBuffer",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Core Media"
    ],
    "preciseIdentifier" : "s:9CoreMedia24CMMutableDataBlockBufferV"
  },
  "title" : "CMMutableDataBlockBuffer"
}
-->

# CMMutableDataBlockBuffer

A block buffer that provides read-write access to a range of bytes.

```
struct CMMutableDataBlockBuffer
```

## Overview

Mutable block buffer provides a contiguous range of data offsets (from 0 to [`count`](/documentation/CoreMedia/CMMutableDataBlockBuffer/count)) a possibly non-contiguous
range of bytes. The bytes referenced by this buffer are mutable.

## Topics

### Classes

[`class MemoryPool`](/documentation/CoreMedia/CMMutableDataBlockBuffer/MemoryPool)

Optimize memory allocations when working with large block buffers.

### Structures

[`struct BlockRegion`](/documentation/CoreMedia/CMMutableDataBlockBuffer/BlockRegion)

A contiguous region of mutable memory within a block buffer.

[`struct BlockSource`](/documentation/CoreMedia/CMMutableDataBlockBuffer/BlockSource)

Provides ability to allocate memory for blocks using custom allocator

### Operators

[`static func += (inout CMMutableDataBlockBuffer, consuming CMMutableDataBlockBuffer)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/+=(_:_:))

Appends the bytes of another block buffer without copying.

### Initializers

[`init(copying: UnsafePointer<AudioBufferList>, blockSource: CMMutableDataBlockBuffer.BlockSource?)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/init(copying:blockSource:))

Creates a block buffer by copying the given audio buffer list.

[`init(count: Int, blockSource: CMMutableDataBlockBuffer.BlockSource?)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/init(count:blockSource:))

Creates a block buffer with `count` number of bytes.

[`init(subBlockCapacity: Int, blockSource: CMMutableDataBlockBuffer.BlockSource?)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/init(subBlockCapacity:blockSource:))

Creates a block buffer with at least `subBlockCapacity` number of sub blocks.

[`init(unsafeBlockBuffer: sending CMBlockBuffer)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/init(unsafeBlockBuffer:))

Creates a mutable block buffer from an existing block buffer.

### Instance Properties

[`var attachments: CMMutableDataBlockBuffer.Attachments`](/documentation/CoreMedia/CMMutableDataBlockBuffer/attachments-swift.property)

[`var count: Int`](/documentation/CoreMedia/CMMutableDataBlockBuffer/count)

The number of bytes in the block buffer.

[`var endIndex: Int`](/documentation/CoreMedia/CMMutableDataBlockBuffer/endIndex)

The position one greater than the last valid subscript argument.

[`var indices: CMMutableDataBlockBuffer.Indices`](/documentation/CoreMedia/CMMutableDataBlockBuffer/indices-swift.property)

The indices that are valid for subscripting the collection, in ascending order.

[`var isContiguous: Bool`](/documentation/CoreMedia/CMMutableDataBlockBuffer/isContiguous)

Determine whether the block buffer is contiguous.

[`var isEmpty: Bool`](/documentation/CoreMedia/CMMutableDataBlockBuffer/isEmpty)

Indicates whether the block buffer is empty.

[`var startIndex: Int`](/documentation/CoreMedia/CMMutableDataBlockBuffer/startIndex)

The position of the first element.

### Instance Methods

[`func append(referenceOf: consuming CMMutableDataBlockBuffer, range: Range<Int>?, optimizeDepth: Bool)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/append(referenceOf:range:optimizeDepth:))

Append a reference to a range of another block buffer.

[`func copyBytes(to: UnsafeMutableRawBufferPointer)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/copyBytes(to:))

Copy all bytes to the destination buffer.

[`func copyBytes<R>(to: UnsafeMutableRawBufferPointer, from: R)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/copyBytes(to:from:))

Copy the bytes from the given range to the destination buffer.

[`func extend(by: Int)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/extend(by:))

Extend block buffer by appending a memory block of count bytes.

[`func isRangeContiguous(Range<Int>) -> Bool`](/documentation/CoreMedia/CMMutableDataBlockBuffer/isRangeContiguous(_:))

Returns true if the given range refers to a contiguous block of memory.

[`func replaceAll(repeating: UInt8)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/replaceAll(repeating:))

Replace all bytes in the buffer with the given byte.

[`func replaceAll(with: UnsafeRawBufferPointer)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/replaceAll(with:)-4sg07)

Replace all data in the buffer with new bytes.

[`func replaceAll(with: some DataProtocol)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/replaceAll(with:)-6jidg)

Replace all data in the buffer with new bytes.

[`func replaceSubrange(Range<Int>, repeating: UInt8)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/replaceSubrange(_:repeating:))

Fill a range in the buffer with given byte.

[`func replaceSubrange(Range<Int>, with: some DataProtocol)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/replaceSubrange(_:with:)-5w62q)

Replace a range of bytes in the block buffer.

[`func replaceSubrange(Range<Int>, with: UnsafeRawBufferPointer)`](/documentation/CoreMedia/CMMutableDataBlockBuffer/replaceSubrange(_:with:)-7rqdy)

Replace a range of bytes in the block buffer.

[`func withContiguousMutableStorageIfAvailable<R>(in: Range<Int>?, (UnsafeMutableRawBufferPointer) throws -> sending R) rethrows -> sending R?`](/documentation/CoreMedia/CMMutableDataBlockBuffer/withContiguousMutableStorageIfAvailable(in:_:))

Access contents of the buffer if available as contiguous memory block.

[`func withContiguousStorageIfAvailable<R>(in: Range<Int>?, (UnsafeRawBufferPointer) throws -> sending R) rethrows -> sending R?`](/documentation/CoreMedia/CMMutableDataBlockBuffer/withContiguousStorageIfAvailable(in:_:))

Access contents of the buffer if available as contiguous memory block.

[`func withUnsafeBlockBuffer<R>((CMBlockBuffer) throws -> sending R) rethrows -> sending R`](/documentation/CoreMedia/CMMutableDataBlockBuffer/withUnsafeBlockBuffer(_:))

Access the underlying CMBlockBuffer instance.

[`func withUnsafeBlockRegions<R>(([CMReadOnlyDataBlockBuffer.BlockRegion]) throws -> sending R) rethrows -> sending R`](/documentation/CoreMedia/CMMutableDataBlockBuffer/withUnsafeBlockRegions(_:))

Access the potentially non-contiguous memory region referenced by this block buffer.

[`func withUnsafeMutableBlockRegions<R>(([CMMutableDataBlockBuffer.BlockRegion]) throws -> sending R) rethrows -> sending R`](/documentation/CoreMedia/CMMutableDataBlockBuffer/withUnsafeMutableBlockRegions(_:))

Access the potentially non-contiguous memory region referenced by this block buffer.

### Subscripts

[`subscript(Int) -> UInt8`](/documentation/CoreMedia/CMMutableDataBlockBuffer/subscript(_:))

Accesses the data byte at the specified position.

### Type Aliases

[`typealias Attachments`](/documentation/CoreMedia/CMMutableDataBlockBuffer/Attachments-swift.typealias)

[`typealias Index`](/documentation/CoreMedia/CMMutableDataBlockBuffer/Index)

[`typealias Indices`](/documentation/CoreMedia/CMMutableDataBlockBuffer/Indices-swift.typealias)

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)