arr->num_alloc = 1;
arr->num_elements = 0;
arr->the_elements = malloc(arr->element_size * arr->num_alloc);
+ if (arr->the_elements == NULL) {
+ abort();
+ }
}
++arr->num_elements;
if (arr->num_elements > arr->num_alloc) {
arr->num_alloc = arr->num_alloc * 2; // whenever we exceed the buffer size, we double it.
arr->the_elements = realloc(arr->the_elements, (arr->element_size * arr->num_alloc));
+ if (arr->the_elements == NULL) {
+ abort();
+ }
}
memcpy((arr->the_elements + ( (arr->num_elements-1) * arr->element_size )), new_element, arr->element_size);
return;
}
+ if (index < 0) { // If the supplied index is invalid, return quietly.
+ return;
+ }
+
--arr->num_elements;
if (index == arr->num_elements) { // If we deleted the element at the end, there's no more to be done.