Contents

dispatch_data_create

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

Declaration

extern dispatch_data_t dispatch_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 to use the default destructor for dispatch objects. Specify 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 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 constant for the destructor, the system simply frees the associated memory inline.

See Also

Creating a Dispatch Data Object