<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/dispatch_data_create",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "c:@F@dispatch_data_create"
  },
  "title" : "dispatch_data_create"
}
-->

# dispatch_data_create

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

```
extern dispatch_data_tdispatch_data_create(const void *buffer, size_t size, dispatch_queue_t queue, dispatch_block_t destructor);
```

## Parameters

`buffer`

A contiguous buffer of memory containing the desired data.

`size`

The size of `buffer`, measured in bytes.

`queue`

The queue on which to call `destructor` when it is time to release the data object. The queue is retained by the data object.

`destructor`

The block responsible for releasing the memory associated with the data object. Specify [`DISPATCH_DATA_DESTRUCTOR_DEFAULT`](/documentation/Dispatch/DISPATCH_DATA_DESTRUCTOR_DEFAULT) to use the default destructor for dispatch objects. Specify [`DISPATCH_DATA_DESTRUCTOR_FREE`](/documentation/Dispatch/DISPATCH_DATA_DESTRUCTOR_FREE) to use the destructor for malloc-based buffers.

## Return Value

A new data object containing the desired data. This object is retained initially. It is your responsibility to release the data object when you are done using it.

## Discussion

If buffer is `NULL` or size is `0`, this function returns an empty dispatch object.

## Discussion

If you specify the default destructor using the [`DISPATCH_DATA_DESTRUCTOR_DEFAULT`](/documentation/Dispatch/DISPATCH_DATA_DESTRUCTOR_DEFAULT) constant, this function creates a copy of the data in `buffer` and manages that data internally. If you specify any other value, this function stores a pointer to your buffer and leaves the responsibility of releasing that buffer to the destructor you provide.

When you release the last reference to the object, the system typically enqueues the block in `destructor` on the provided queue. However, if you specify the [`DISPATCH_DATA_DESTRUCTOR_FREE`](/documentation/Dispatch/DISPATCH_DATA_DESTRUCTOR_FREE) constant for the destructor, the system simply frees the associated memory inline.

---

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)