language: C (gcc-4.7.2)
date: 979 days 8 hours ago
link:
visibility: public
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
#include <stdio.h>
#include <stdlib.h>
 
struct RingBuffer {
        size_t head;
        size_t tail;
        size_t count;
        size_t size;
        char *rbArray[];
};
 
struct RingBuffer *rb_create(size_t nelems){
        struct RingBuffer *new;
        new = malloc(sizeof *new + nelems * sizeof *new->rbArray);
        if (new) {
                /* for (size_t i = 0; i < nelems; i++)
                        new->rbArray[i] = NULL; */
                new->head = new->tail = new->count = 0;
                new->size = nelems;
        }
        return new;
}
 
int main(void) {
        struct RingBuffer *rb = rb_create(100);
        printf("head: %d\ntail: %d\ncount: %d\n",
                (int)rb->head, (int)rb->tail, (int)rb->count);
        free(rb);
        return 0;
}