c - Move a pointer location around to write a recursively allocated buffer -
c - Move a pointer location around to write a recursively allocated buffer -
apologies if title doesn't create sense, i've been staring @ monitor 15 minutes trying come one.
i'm using library function c api (in 64-bit xubuntu 14.04) move set number of int16_t values buffer , repeat set number of times, described here in (sort of) pseudo-code:
int16_t *buffer = calloc(total_values_to_receive, 2 * sizeof(samples[0])); while (!done){ receive_into_buffer(buffer, num_values_to_receive_per_pass); fwrite(buffer, 2 * sizeof(samples[0]), num_values_to_receive_per_pass, file); values_received += num_values_to_receive_per_pass; if (values_received == total_values_to_receive){ done = true; } }
basically receive set number of values on each pass , writes values file, note same file appended each time. e.g. if total_values_to_receive = 100
, num_values_to_receive_per_pass = 10
, there 10 passes in total.
what do, increment speed, have write part occur after passes have been completed. library function prototype contains void* samples, size_t num_samples
, which, guessed it, refers buffer samples need stored , amount of samples store.
i'm not confident pointers, there way write buffer on 1 pass, , move pointer num_values_to_receive_per_pass
next time library function called, appends buffer (so speak). pointer can moved start of buffer , fwrite
can called write total number of values file.
does create sense? tips on how implement it?
thanks in advance.
assuming sec argument of receive_into_buffer
in unit of buffer element, not byte, next should work,
int16_t *buffer = calloc(total_values_to_receive, 2 * sizeof(buffer[0])); int16_t *temp = buffer; while (!done){ receive_into_buffer(temp, num_values_to_receive_per_pass); temp += 2 * num_values_to_receive_per_pass; values_received += num_values_to_receive_per_pass; if (values_received == total_values_to_receive){ done = true; } } fwrite(buffer, 2 * sizeof(buffer[0]), total_values_to_receive, file);
c void-pointers
Comments
Post a Comment