-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.c
69 lines (56 loc) · 1.75 KB
/
demo.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <stdlib.h>
#include "ringBuffer.h"
typedef struct {
int j;
} myStruct;
void printArray(myStruct a[], int len) {
printf("\n");
for (int i = 0; i < len; i++) {
printf(" %u", a[i].j);
}
}
int main() {
ringBuffer* buffer = rb_create(7, sizeof(myStruct));
myStruct a[buffer->len];
for (int i = 1; i < 11; i++) {
myStruct ms = {i};
rb_write(buffer, &ms);
rb_dump(buffer, a);
printArray(a, rb_fillLevel(buffer));
printf(" fillLevel: %zu", rb_fillLevel(buffer));
printf(" head: %zu", buffer->head);
printf(" tail: %zu", buffer->tail);
printf(" --- rb_write(), rb_dump()");
}
printf("\n");
for (int i = 9; i < 14; i++) {
myStruct ms = {i};
rb_overWrite(buffer, &ms);
rb_dump(buffer, a);
printArray(a, rb_fillLevel(buffer));
printf(" fillLevel: %zu", rb_fillLevel(buffer));
printf(" head: %zu", buffer->head);
printf(" tail: %zu", buffer->tail);
printf(" --- rb_overWrite(), rb_dump()");
}
printf("\n");
for (int i = 0; i < 3; i++) {
myStruct ms = {0};
rb_read(buffer, &ms);
printf("\n %u", ms.j);
printf(" fillLevel: %zu", rb_fillLevel(buffer));
printf(" head: %zu", buffer->head);
printf(" tail: %zu", buffer->tail);
printf(" --- rb_read()");
}
printf("\n");
rb_dump(buffer, a);
printArray(a, rb_fillLevel(buffer));
printf(" fillLevel: %zu", rb_fillLevel(buffer));
printf(" head: %zu", buffer->head);
printf(" tail: %zu", buffer->tail);
printf(" --- rb_dump()\n");
rb_destroy(buffer);
return 0;
}