int main (void) { srand (42); dynarray_t *arr = dynarray_create (4, sizeof (test_t), 1); // Add 10 random elements... int i; for (i = 0; i < 10; i++) { test_t heh = { rand (), rand () }; dynarray_push (arr, &heh); } // Change one element to something different test_t something = { 1, 2 }; dynarray_insert (arr, &something, 0); // Pop top element, print out its numbers... test_t popped; dynarray_pop (arr, &popped); printf ("Pop test: %i and %i\n", popped.a, popped.b); // Clear 6th element dynarray_clear (arr, 5); // Now loop and get the rest of the elements, avoiding NULLs for (i = 0; i < 16; i++) { test_t *t = (test_t *)arr->index [i]; if (t && i < arr->e_max) printf ("%i: %i and %i\n", i, t->a, t->b); } // Free: dynarray_delete (&arr); return 0; }
static void probe_layers_clear(probe_t * probe) { dynarray_clear(probe->layers, (ELEMENT_FREE) layer_free); }
inline void algorithm_instance_clear_events(algorithm_instance_t * instance) { if (instance) { dynarray_clear(instance->events, (void (*)(void*)) event_free); } }