Skip to content

rikvdh/zringbuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zringbuf

Build Status

Zero-Allocation ring-buffer in C

Installation

With clib:

clib install rikvdh/zringbuf

Example

#include "zringbuf.h"
#include <assert.h>

// Create ring-buffer called 'buf' with size of 100 bytes
ZRINGBUF_DECL(buf, 100)

int main(int argc, char **argv)
{
    zringbuf_queue(&buf, 'a');

    zringbuf_queue_arr(&buf, "bcd", 3);

    assert(4 == zringbuf_size_used(&buf));

    char ch;

    assert(true == zringbuf_dequeue(&buf, &ch));
    assert(ch == 'a');

    return 0;
}