Skip to content

incrediblejr/ijcringbuffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

ijcringbuffer.h - v0.01 - public domain - @incrediblejr, Dec 2015

no warranty implied; use at your own risk

A continuous ringbuffer ala @rygorous 'magic ring buffer' (without the magic)

ABOUT

ijcringbuffer is a ringbuffer that handles variable sized commands/data, inspired by @rygorous blog post about the 'magic ring buffer' (but implemented sans the magic).

The ring buffer guarantees that data will written as-is or not at all (no splitting). This can be used when the consumer expects the data be linear in memory.

Usage examples (and tests) is at the bottom of the file in the IJCRINGBUFFER_TEST section.

USAGE

The ringbuffer is implemented as a stb-style header-file library which means that in ONE source file, put:

#define IJCRINGBUFFER_IMPLEMENTATION
// if custom assert and memcpy is wanted/needed
// (and no dependencies on assert.h + string.h)
// you can define/override the default by :
// #define IJCRB_assert   custom_assert
// #define IJCRB_memcpy   custom_memcpy
#include "ijcringbuffer.h"

Other source files should just include ijcringbuffer.h

NOTES

There are a myriad of ways to implement said ring buffer, especially if you would allow the producer to modify the read-cursor (but you have to have some standards).

I also wanted to solve the (not-in-real-life-?) problem when the read-cursor catches up with the write-cursor, giving the producer only part of the buffer (worst case half of the buffer) to write into, when we should be able to start writing to the start of the buffer (essentially doing a buffer reset).

LICENSE

This software is in the public domain. Where that dedication is not recognized, you are granted a perpetual, irrevocable license to copy, distribute, and modify this file as you see fit.

About

a ring buffer for variable sized continuous data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages