36 #define CX_BUFFER_AUTO_EXTEND |
36 #define CX_BUFFER_AUTO_EXTEND |
37 #define CX_BUFFER_COPY_ON_WRITE |
37 #define CX_BUFFER_COPY_ON_WRITE |
38 #define CX_BUFFER_COPY_ON_EXTEND |
38 #define CX_BUFFER_COPY_ON_EXTEND |
39 ``` |
39 ``` |
40 |
40 |
41 <warning> |
41 For creating a UCX buffer you have two options: initialize a pre-allocated structure, or allocate and initialize a new structure in one call. |
42 TODO: document |
42 |
43 </warning> |
43 For the first option, you can call `cxBufferInit()` with the `buffer` argument pointing to an uninitialized `CxBuffer` structure. |
|
44 You can pass a pre-allocated `space`, the desired `capacity`, and an `allocator`. |
|
45 If `space` is `NULL`, the `allocator` is used to allocate enough space to match the desired `capacity`. |
|
46 |
|
47 The `flags` argument is a bit-wise-or combination of the constants listed below. |
|
48 |
|
49 The function `cxBufferCreate()` is equivalent, except that it uses the `allocator` to allocate a new `CxBuffer` structure, instead of initializing an existing one. |
|
50 |
|
51 If any allocation fails, `cxBufferInit()` returns non-zero, or `cxBufferCreate()` returns `NULL`, respectively. |
44 |
52 |
45 | Flag | Description | |
53 | Flag | Description | |
46 |--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
54 |--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
47 | CX_BUFFER_DEFAULT | Alias for zero, meaning no flags are set. | |
55 | CX_BUFFER_DEFAULT | Alias for zero, meaning no flags are set. | |
48 | CX_BUFFER_FREE_CONTENTS | When the buffer structure is [destroyed](#destroy), the memory for the contents is also automatically deallocated. | |
56 | CX_BUFFER_FREE_CONTENTS | When the buffer structure is [destroyed](#destroy), the memory for the contents is also automatically deallocated. | |