| 26 | }; |
| 27 | |
| 28 | CircularBuffer CircularBuffer_New |
| 29 | ( |
| 30 | size_t item_size, // size of item in bytes |
| 31 | uint cap // max number of items in buffer |
| 32 | ) { |
| 33 | CircularBuffer cb = rm_calloc(1, sizeof(_CircularBuffer) + item_size * cap); |
| 34 | |
| 35 | cb->read = cb->data; // read from beginning of data |
| 36 | cb->write = 0; // write to beginning of data |
| 37 | cb->item_cap = cap; // buffer capacity |
| 38 | cb->item_size = item_size; // item size |
| 39 | cb->item_count = 0; // no items in buffer |
| 40 | cb->end_marker = cb->data + (item_size * cap); |
| 41 | |
| 42 | return cb; |
| 43 | } |
| 44 | |
| 45 | // returns number of items in buffer |
| 46 | uint64_t CircularBuffer_ItemCount |