docs/Writerside/topics/array_list.h.md

changeset 1318
12fa1d37fe48
parent 1248
fc5e63b04281
equal deleted inserted replaced
1317:eeb2fc3850e2 1318:12fa1d37fe48
64 > Using `CX_ARRAY_DECLARE_SIZED()` can save some space when you are using a size type that is _half_ as wide as `sizeof(void*)`. 64 > Using `CX_ARRAY_DECLARE_SIZED()` can save some space when you are using a size type that is _half_ as wide as `sizeof(void*)`.
65 > On 64-bit architectures, having the possibility to store more than four billion items is rarely necessary, hence using 32-bit integers for size and capacity 65 > On 64-bit architectures, having the possibility to store more than four billion items is rarely necessary, hence using 32-bit integers for size and capacity
66 > saves eight bytes (assuming proper alignment in your struct). 66 > saves eight bytes (assuming proper alignment in your struct).
67 67
68 Once the array is declared, you can use one of the macros `cx_array_initialize()` or `cx_array_initialize_a()` to allocate memory. 68 Once the array is declared, you can use one of the macros `cx_array_initialize()` or `cx_array_initialize_a()` to allocate memory.
69 The former uses a stdlib default allocator and the latter allows you to use a specific allocator. 69 The former uses the [default allocator](allocator.h.md#default-allocator) and the latter allows you to use a specific allocator.
70 Important to note is, that the `ARRAY` argument expects the variable's _name_. 70 Important to note is, that the `ARRAY` argument expects the variable's _name_.
71 The macros set `ARRAY_size` to zero, `ARRAY_capacity` to the specified initial capacity, and invoke the allocator's `malloc()` function to allocate the memory. 71 The macros set `ARRAY_size` to zero, `ARRAY_capacity` to the specified initial capacity, and invoke the allocator's `malloc()` function to allocate the memory.
72 72
73 Using the example from above, and the UCX [memory pool](mempool.h.md), this could look like this: 73 Using the example from above, and the UCX [memory pool](mempool.h.md), this could look like this:
74 74
112 The main purpose of the functions defined in the array list header, 112 The main purpose of the functions defined in the array list header,
113 is to make it easier to write to an array without caring too much about a possibly needed reallocation. 113 is to make it easier to write to an array without caring too much about a possibly needed reallocation.
114 114
115 This is realized by passing a reallocator to the various functions which specifies how an array shall be reallocated when needed. 115 This is realized by passing a reallocator to the various functions which specifies how an array shall be reallocated when needed.
116 116
117 The default `cx_array_default_reallocator` simply defers to the standard library `realloc()`. 117 The default `cx_array_default_reallocator` simply defers to the [default allocator](allocator.h.md#default-allocator).
118 118
119 A reallocator created with the `cx_array_reallocator()` function uses a more sophisticated approach. 119 A reallocator created with the `cx_array_reallocator()` function uses a more sophisticated approach.
120 On the one hand, it can use an arbitrary UCX [allocator](allocator.h.md) for the reallocation, 120 On the one hand, it can use an arbitrary UCX [allocator](allocator.h.md) for the reallocation,
121 and on the other hand, it can optionally keep track of a stack memory pointer. 121 and on the other hand, it can optionally keep track of a stack memory pointer.
122 If you pass a non-`NULL` pointer to `stackmem`, the reallocator will _always_ allocate _new_ memory for the array, 122 If you pass a non-`NULL` pointer to `stackmem`, the reallocator will _always_ allocate _new_ memory for the array,

mercurial