I have a buffer of binary data:
SInt16 *buffer = (SInt16 *)calloc(1024,sizeof(SInt16));
I want to process a chunk of data off the front of this buffer (for example 50 data points)
for(int i = 0; i < 50 ; ++i){
process_data(buffer[i])
}
Once the data is processed I don’t need it any more, so I want to discard it and place my pointer *buffer at the 51st data point. However, I still need buffer to point to a buffer that has 1024 places in it. To do this I thought I would do a bit shift to do this because it accomplishes my goal and, to my knowledge, is quick (I’m in a high priority thread). However I’m unclear how bit shifting works with byte arrays.
First, if I want to shift the array such that *buffer points to the value formerly contained in buffer[50], is that a left or a right shift in C (Objective C)?
Second, if I shift buffer will it shift all 1024 data points or will it only shift one SInt16 datapoint at buffer[0]?
The idea here is that a processor will read chunks off the beginning of the buffer and then signal a file reader on another thread to append new data to the end of buffer. If 50 data points are processed, then those 50 points are discarded, and the file reader appends 50 new points of data to the end of the byte buffer.
Bit shifting has nothing to do with arrays / buffers.
You could move the data around in the buffer via copying, but that’s incredibly inefficient.
You really should think about using/implementing a circular buffer for this.