1 .\" Copyright (c) 2010 Apple Inc. All rights reserved.
3 .Dt dispatch_data_create 3
6 .Nm dispatch_data_create ,
7 .Nm dispatch_data_create_concat ,
8 .Nm dispatch_data_create_subrange ,
9 .Nm dispatch_data_create_map ,
10 .Nm dispatch_data_apply ,
11 .Nm dispatch_data_copy_region ,
12 .Nm dispatch_data_get_size
13 .Nd create and manipulate dispatch data objects
15 .Fd #include <dispatch/dispatch.h>
17 .Fo dispatch_data_create
18 .Fa "const void* buffer"
20 .Fa "dispatch_queue_t queue"
21 .Fa "dispatch_block_t destructor"
24 .Fo dispatch_data_create_concat
25 .Fa "dispatch_data_t data1"
26 .Fa "dispatch_data_t data2"
29 .Fo dispatch_data_create_subrange
30 .Fa "dispatch_data_t data"
35 .Fo dispatch_data_create_map
36 .Fa "dispatch_data_t data"
37 .Fa "const void **buffer_ptr"
38 .Fa "size_t *size_ptr"
41 .Fo dispatch_data_apply
42 .Fa "dispatch_data_t data"
43 .Fa "bool (^applier)(dispatch_data_t, size_t, const void *, size_t)"
46 .Fo dispatch_data_copy_region
47 .Fa "dispatch_data_t data"
49 .Fa "size_t *offset_ptr"
52 .Fo dispatch_data_get_size
53 .Fa "dispatch_data_t data"
55 .Vt dispatch_data_t dispatch_data_empty ;
57 Dispatch data objects are opaque containers of bytes that represent one or more
58 regions of memory. They are created either from memory buffers managed by the
59 application or the system or from other dispatch data objects. Dispatch data
60 objects are immutable and the memory regions they represent are required to
61 remain unchanged for the lifetime of all data objects that reference them.
62 Dispatch data objects avoid copying the represented memory as much as possible.
63 Multiple data objects can represent the same memory regions or subsections
67 .Fn dispatch_data_create
68 function creates a new dispatch data object of given
74 block will be submitted to the specified
76 when the object reaches the end of its lifecycle, indicating that the system no
79 This allows the application to deallocate
80 the associated storage. The
82 argument is ignored if one of the following predefined destructors is passed:
83 .Bl -tag -width DISPATCH_DATA_DESTRUCTOR_DEFAULT -compact -offset indent
84 .It DISPATCH_DATA_DESTRUCTOR_FREE
85 indicates that the provided buffer can be deallocated with
88 .It DISPATCH_DATA_DESTRUCTOR_DEFAULT
89 indicates that the provided buffer is not managed by the application and should
90 be copied into memory managed and automatically deallocated by the system.
94 .Fn dispatch_data_create_concat
95 function creates a new data object representing the concatenation of the memory
96 regions represented by the provided data objects.
99 .Fn dispatch_data_create_subrange
100 function creates a new data object representing the sub-region of the provided
102 object specified by the
109 .Fn dispatch_data_create_map
110 function creates a new data object by mapping the memory represented by the
113 object as a single contiguous memory region (moving or copying memory as
120 they are filled with the location and extent of the contiguous region, allowing
121 direct read access to the mapped memory. These values are valid only as long as
122 the newly created object has not been released.
125 .Fn dispatch_data_apply
126 function provides read access to represented memory without requiring it to be
127 mapped as a single contiguous region. It traverses the memory regions
130 argument in logical order, invokes the specified
132 block for each region and returns a boolean indicating whether traversal
133 completed successfully. The
135 block is passed the following arguments for each memory region and returns a
136 boolean indicating whether traversal should continue:
137 .Bl -tag -width "dispatch_data_t rgn" -compact -offset indent
138 .It Fa "dispatch_data_t rgn"
139 data object representing the region
140 .It Fa "size_t offset"
141 logical position of the region in
143 .It Vt "const void *loc"
144 memory location of the region
150 data object is released by the system when the
153 The associated memory location
155 is valid only as long as
157 has not been deallocated; if
159 is needed outside of the
163 object must be retained in the block.
166 .Fn dispatch_data_copy_region
167 function finds the contiguous memory region containing the logical position
170 argument among the regions represented by the provided
172 object and returns a newly created copy of the data object representing that
173 region. The variable specified by the
175 argument is filled with the logical position where the returned object starts
181 .Fn dispatch_data_get_size
182 function returns the logical size of the memory region or regions represented
186 .Sh EMPTY DATA OBJECT
188 .Vt dispatch_data_empty
189 object is the global singleton object representing a zero-length memory region.
190 It is a valid input to any dispatch_data functions that take data object
193 Dispatch data objects are retained and released via calls to
196 .Fn dispatch_release .
197 Data objects passed as arguments to a dispatch data
201 function can be released when the function returns. The newly created object
202 holds implicit references to their constituent memory regions as necessary.
205 .Xr dispatch_object 3 ,
206 .Xr dispatch_io_read 3