Giter Club home page Giter Club logo

ringbuffer's Introduction

ringbuffer

Cross platform lock free ringbuffer. Support one reader and one writter,or multi reader and one writter.
NOT SUPPORT MULTI READER AND MULTI WRITTER or ONE READER AND MULTI WRITTER.
If you want to multi writter, you should create multi ringbuffer.

How to use?

  • Just include atomic_ops.h ring_buffer.h ring_buffer.cpp to your Makefile or other else.
  • In the source folder,and make will compile a test bin for you.

Sample

How to push

void *p_mem = malloc(RB_SIZE);
RingBuffer rb(RB_SIZE, false, false);
rb_ctx ctx;
rb.push(&ctx, sizeof(ctx), p_mem);

How to pop

rb_ctx ctx;
unsigned int len = 0;
rb.pop(&ctx, &len, p_mem); //p_mem same buffer as push

And an other way to get data

For better performarce, you can get data without copy it to an other buffer.

unsigned int len = 0;
rb_ctx *p_ctx = (rb_ctx*)rb.peek(&len, 0, p_mem);
//processing data
rb.remove(p_mem);

Also more example about how to use, please refer to test_ring_buffer.cpp

Performance

You can run ./test after compile.
On my mbp(Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz).
Actually, not like epoll/poll,CPU is wasted on asking.

Bytes Size Method QPS
32 pop 12479897
32 peek 11002642

ringbuffer's People

Contributors

jeehou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.