Paraslash Audio Streaming | |
About News Download Documentation Development |
Simple ringbuffer implementation. More...
Functions | |
struct ringbuffer * | ringbuffer_new (unsigned size) |
Initialize a new ringbuffer. More... | |
void * | ringbuffer_add (struct ringbuffer *rb, void *data) |
Add one entry to a ringbuffer. More... | |
void * | ringbuffer_get (struct ringbuffer *rb, int num) |
Get one entry from a ringbuffer. More... | |
unsigned | ringbuffer_filled (struct ringbuffer *rb) |
Get the number of entries in the ring buffer. More... | |
Simple ringbuffer implementation.
struct ringbuffer* ringbuffer_new | ( | unsigned | size | ) |
Initialize a new ringbuffer.
size | The number of entries the ringbuffer holds. |
This function initializes a circular ring buffer which can hold up to size entries of arbitrary type. If performance is an issue, size should be a power of two to make the underlying modulo operations cheap. Arbitrary many ringbuffers may be initialized via this function. Each ringbuffer is identified by a 'cookie'.
References zalloc().
void* ringbuffer_add | ( | struct ringbuffer * | rb, |
void * | data | ||
) |
Add one entry to a ringbuffer.
rb | The ringbuffer identifier. |
data | The data to be inserted. |
Insert data into the ringbuffer associated with cookie. As soon as the ringbuffer fills up, its oldest entry is disregarded and replaced by data.
void* ringbuffer_get | ( | struct ringbuffer * | rb, |
int | num | ||
) |
Get one entry from a ringbuffer.
rb | The ringbuffer identifier. |
num | The number of the entry. |
unsigned ringbuffer_filled | ( | struct ringbuffer * | rb | ) |
Get the number of entries in the ring buffer.
rb | The ringbuffer identifier |