All buffers are allocated at initialization and continuously recycled throughout the life of the stream. Because memory is allocated only once, performance of this technique is slightly faster than the FIFO class CBufferFIFO . An allocated CBufferCircular might look something like the one in Figure 18.1 in memory. As you can see in Figure 18.1, pFirstFullBuffer points to the first buffer with valid data and pFirstEmptyBuffer points to the first buffer available for use. As the data is streaming, full buffers are consumed by a device and empty buffers are filled by the Navigator.
All memory is allocated at the same time and freed at the same time.
Last buffer points to first, a circular buffer scheme. Also, there is no protection against a memory leak if the method is called twice. If you use this code, you might want to add these checks. Notice that the buffer size and amount of buffers is passed to the method, allowing any number of configurations. You can also allocate a circular buffer with respect to the data type.