| 115 |
115 |
| 116 > Be careful when using these functions on an array that was initialized with fixed-sized memory. |
116 > Be careful when using these functions on an array that was initialized with fixed-sized memory. |
| 117 > In this case, you MUST make sure that the capacity is sufficient or reallocate the array |
117 > In this case, you MUST make sure that the capacity is sufficient or reallocate the array |
| 118 > with `cx_array_copy_to_new()` or `cx_array_copy_to_new_a()` before adding or inserting more elements. |
118 > with `cx_array_copy_to_new()` or `cx_array_copy_to_new_a()` before adding or inserting more elements. |
| 119 >{style="note"} |
119 >{style="note"} |
| |
120 |
| |
121 ## Remove Elements |
| |
122 |
| |
123 ```C |
| |
124 #include <cx/array_list.h> |
| |
125 |
| |
126 void cx_array_remove(CxArray array, size_t index); |
| |
127 |
| |
128 void cx_array_remove_fast(CxArray array, size_t index); |
| |
129 |
| |
130 void cx_array_remove_array(CxArray array, size_t index, size_t n); |
| |
131 |
| |
132 void cx_array_remove_array_fast(CxArray array, size_t index, size_t n); |
| |
133 ``` |
| |
134 |
| |
135 The functions `cx_array_remove()` and `cx_array_remove_array()` remove one or more elements from the array by shifting the remaining elements by the number of removed elements. |
| |
136 The functions `cx_array_remove_fast()` and `cx_array_remove_array_fast()` on the other hand copy elements from the end of the array into the gap to fill the removed elements. |
| |
137 Therefore, if the order of the elements does not matter, you can use the fast versions of these functions for better performance. |
| |
138 |
| |
139 > When you specify an `index` that is out-of-bounds or choose a number `n` of elements that would overflow the array, |
| |
140 > the above functions only remove as many elements as possible. |
| |
141 > So it's safe to use them without any bounds checking. |
| 120 |
142 |
| 121 ## Sorting |
143 ## Sorting |
| 122 |
144 |
| 123 ```C |
145 ```C |
| 124 #include <cx/array_list.h> |
146 #include <cx/array_list.h> |