   }
 }
 
+//
+// FIXME: This function is longer than I would like.
+//
 __host__
 cudaError_t af_TimeCurveCopyToHost(afTimeCurve_t* src, afTimeCurve_t** dst, bool assume_contiguous, int count) {
   void* host_mem;
   cudaError_t result;
+  // We want to make sure that we don't try and copy less than we should.
+  if (assume_contiguous && count < 0) {
+    return cudaErrorUnknown;
+  }
   // If it's not contiguous then we'll assume it has a count of 0
   // which means we'll only download the curve struct.
   // From there we'll be able to download the correct array for the pairs.

}

__host__
cudaError_t __af_TimeCurveCopyToDevice(afTimeCurve_t* src, afTimeCurve_t** dst) {
  void* dev_mem;
  cudaError_t result;
  // We attempt to put a whole curve in a contiguous block of memory.

  }
  afTimeCurve_t* host_curve = (afTimeCurve_t*) host_mem;
  // Check that the memory copied actually makes sense.
  if (host_curve->pairs == (afTimeCurvePair_t*) ((char*)src + sizeof(afTimeCurve_t)) && host_curve->count == count) {
    // Copy worked!
    host_curve->pairs = (afTimeCurvePair_t*) host_curve + sizeof(afTimeCurve_t);
    (*dst) = host_curve;
    return result;
  } else if (host_curve->count < 0) {
    // We seem to have copied the incorrect thing...
    return cudaErrorUnknown;
  } else if (host_curve->pairs == (afTimeCurvePair_t*) ((char*)src + sizeof(afTimeCurve_t)) && host_curve->count < count ) {
    // We over allocated on the host. Lets deallocate some memory.
    afTimeCurve_t* new_host_curve = (afTimeCurve_t*) realloc(host_curve, sizeof(afTimeCurve_t) + host_curve->count * sizeof(afTimeCurvePair_t));
    if (new_host_curve == NULL) {
      // Try and free host allocated memory.
      free(host_mem);
      return cudaErrorUnknown;
    }
    host_curve->pairs = (afTimeCurvePair_t*) ((char*)host_curve + sizeof(afTimeCurve_t));
    (*dst) = new_host_curve;
    return result;
  } else if (host_curve->pairs == (afTimeCurvePair_t*) ((char*)src + sizeof(afTimeCurve_t)) && host_curve->count > count) {
    // Extend the memory allocated a bit because we under allocated on the host.
    afTimeCurve_t* new_host_curve = (afTimeCurve_t*) realloc(host_curve, sizeof(afTimeCurve_t) + host_curve->count * sizeof(afTimeCurvePair_t));
    if (new_host_curve == NULL) {
      free(host_mem);
      return cudaErrorUnknown;
    }
    // We'll now copy down the additional pairs.
    afTimeCurvePair_t* dev_start_ptr = (afTimeCurvePair_t*) ((char*)src + count * sizeof(afTimeCurvePair_t));
    int length = new_host_curve->count - count;
    // Use void* here
    afTimeCurvePair_t* host_start_ptr = (afTimeCurvePair_t*) ((char*)new_host_curve + count * sizeof(afTimeCurvePair_t));
    result = cudaMemcpy(host_start_ptr, dev_start_ptr, length * sizeof(afTimeCurvePair_t), cudaMemcpyDeviceToHost);
    if (result != cudaSuccess) {
      free(new_host_curve);
      return result;
    }
    // Fix up the pointer.
    new_host_curve->pairs = (afTimeCurvePair_t*) ((char*)new_host_curve + sizeof(afTimeCurve_t));
    // Return the result.
    (*dst) = new_host_curve;
    return result;
  } else {
    // We copied memory that was unrelated. Lets reallocate what we have and try again.
    afTimeCurve_t* new_host_curve = (afTimeCurve_t*) realloc(host_curve, sizeof(afTimeCurve_t) + host_curve->count * sizeof(afTimeCurvePair_t));
    if(new_host_curve == NULL) {
      free(new_host_curve);
      return cudaErrorUnknown;
    }
    afTimeCurvePair_t* host_start_ptr = (afTimeCurvePair_t*) ((char*)new_host_curve + sizeof(afTimeCurve_t));
    result = cudaMemcpy(host_start_ptr, new_host_curve->pairs, new_host_curve->count * sizeof(afTimeCurvePair_t), cudaMemcpyDeviceToHost);
    if (result != cudaSuccess) {
      free(new_host_curve);
      return cudaErrorUnknown;
    }
    (*dst) = new_host_curve;
    return result;
  }
}
