not as optimized as a system realloc but I've had to do this often enough manually to justify a utility function.