-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer_manager.c
41 lines (32 loc) · 916 Bytes
/
buffer_manager.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "ring_buffer.h"
const int SIMPLE_BUFFER_SIZE = 5;
const int RING_BUFFER_SIZE = 4;
/* function declaration */
int main()
{
// create simple buffer
char simple_buffer[SIMPLE_BUFFER_SIZE];
// create our buffer and a handler pointer to facilitate operations
char *buffer = malloc(RING_BUFFER_SIZE * sizeof(char));
cbuf_handle_t cbuf = circular_buf_init(buffer, RING_BUFFER_SIZE);
// fill circular buffer with data from simple buffer
circular_buf_put(cbuf, 'a');
circular_buf_put(cbuf, 'b');
circular_buf_put(cbuf, 'c');
circular_buf_put(cbuf, 'd');
circular_buf_put(cbuf, 'e');
printf("\n******\nReading back values: ");
while(!circular_buf_empty(cbuf))
{
char data;
circular_buf_get(cbuf, &data);
printf("%c ", data);
}
free(buffer);
circular_buf_free(cbuf);
return 0;
}