Originally Posted by
Adak
#1)
Divide it up into 2 halves, (A & B). The goal here is to stop the slow down that would be needed by shuffling data from the end of the buffer, to the start of it, as new data is being received. That's a performance killer in a large buffer.
Your buffer will be a multiple of 16 and BUFSIZE (if possible), on your system. (BUFSIZE is a macro your compiler will have that is moderate in size, but optimized for system performance. 1024 bytes is a good starting point to test). As the A half is being filled with data, all is well. B half is empty (and set to zero by using calloc when it's allocated, as was A half, before it).
When A is full, then B begins filling, and at the same time, A begins writing out it's data. When A is out of data, B is full, so A becomes the active receiver of data, and is memset to zero. B begins writing out data now, stressing that this is happening at the same time.
The effect of this synchronicity, is that throughput is greatly enhanced, and no shuffling of data from the end of the buffer to the start of the buffer, is needed. All while achieving FIFO.