#include "dynarr.h" /// Allocate a new DynArrHeader with count=0 and capacity=0. /// Returns a pointer to the data region immediately following the header. void *new_header(void) { DynArrHeader *h = malloc(sizeof(DynArrHeader)); exists(h); h->count = 0; h->capacity = 0; return h + 1; } /// Return a tight copy of arr (capacity == count). /// elem_size is the size of one element in bytes. void *copy_header(void *arr, size_t elem_size) { DynArrHeader *src = da_header(arr); size_t bytes = sizeof(DynArrHeader) + src->count * elem_size; DynArrHeader *dst = malloc(bytes); exists(dst); memcpy(dst, src, bytes); dst->capacity = dst->count; return dst + 1; }