<!--
{
  "documentType" : "article",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/dispatch-data",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Dispatch Data"
}
-->

# Dispatch Data

An object that manages a memory-based data buffer and exposes it as a contiguous block of memory.

## Discussion

The memory buffer managed by this object may be a single contiguous block of memory, or it may consist of multiple discontiguous blocks. For the discontiguous case, the dispatch data object makes it appear as if the memory is contiguous.

## Topics

### Creating a Dispatch Data Object

[`extern dispatch_data_tdispatch_data_create(const void *buffer, size_t size, dispatch_queue_t queue, dispatch_block_t destructor);`](/documentation/Dispatch/dispatch_data_create)

Creates a new dispatch data object with the specified memory buffer.

[`extern dispatch_data_tdispatch_data_create_map(dispatch_data_t data, const void **buffer_ptr, size_t *size_ptr);`](/documentation/Dispatch/dispatch_data_create_map)

Returns a new dispatch data object containing a contiguous representation of the specified object’s memory.

[`extern dispatch_data_tdispatch_data_create_concat(dispatch_data_t data1, dispatch_data_t data2);`](/documentation/Dispatch/dispatch_data_create_concat)

Returns a new dispatch data object consisting of the concatenated data from two other data objects.

[`extern dispatch_data_tdispatch_data_create_subrange(dispatch_data_t data, size_t offset, size_t length);`](/documentation/Dispatch/dispatch_data_create_subrange)

Returns a new dispatch data object whose contents consist of a portion of another object’s memory region.

[`extern dispatch_data_tdispatch_data_copy_region(dispatch_data_t data, size_t location, size_t *offset_ptr);`](/documentation/Dispatch/dispatch_data_copy_region)

Returns a data object containing a portion of the data in another data object.

[`#define dispatch_data_empty`](/documentation/Dispatch/dispatch_data_empty)

A dispatch data object representing a zero-length memory region.

[`typealias dispatch_data_t`](/documentation/Dispatch/dispatch_data_t)

An immutable object representing a contiguous or sparse region of memory.

[`@protocol OS_dispatch_data <OS_dispatch_object>`](/documentation/Dispatch/OS_dispatch_data)

[`#define DISPATCH_DATA_DESTRUCTOR_DEFAULT`](/documentation/Dispatch/DISPATCH_DATA_DESTRUCTOR_DEFAULT)

The default data destructor for dispatch objects.

[`#define DISPATCH_DATA_DESTRUCTOR_FREE`](/documentation/Dispatch/DISPATCH_DATA_DESTRUCTOR_FREE)

The destructor for dispatch data objects whose memory buffer was created using the malloc family of allocation routines.

### Getting the Number of Elements

[`extern size_t dispatch_data_get_size(dispatch_data_t data);`](/documentation/Dispatch/dispatch_data_get_size)

Returns the logical size of the memory managed by a dispatch data object

### Applying Changes to the Data

[`extern bool dispatch_data_apply(dispatch_data_t data, dispatch_data_applier_t applier);`](/documentation/Dispatch/dispatch_data_apply)

Traverses the memory of a dispatch data object and executes custom code on each region.

[`typedef _Bool (^)(NSObject<OS_dispatch_data> *, unsigned long, const void *, unsigned long) dispatch_data_applier_t;`](/documentation/Dispatch/dispatch_data_applier_t)

A block to invoke for every contiguous memory region in a data object.



---

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)