Giter Site home page Giter Site logo

vitalyvch / rng_buf Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 5.0 222 KB

An optimized Ring Buffer implementation based on the POSIX shared memory trick

License: Other

CMake 0.31% C++ 98.58% C 1.12%
buffer ring-buffer ringbuffer circular-buffer circularbuffer c library

rng_buf's Introduction

rng_buf

This is an optimized Ring Buffer implementation using the POSIX shared memory trick.

This implementation is much more convenient in use then classical implementations, also there is some benefit in CPU usage.

A circular-buffer implementation is optimized by mapping the underlying buffer to two contiguous regions of virtual memory. (Naturally, the underlying buffer‘s length must then equal some multiple of the system’s page size.) Reading from and writing to the circular buffer may then be carried out with greater efficiency by means of direct memory access; those accesses which fall beyond the end of the first virtual-memory region will automatically wrap around to the beginning of the underlying buffer. When the read offset is advanced into the second virtual-memory region, both offsets—read and write—are decremented by the length of the underlying buffer.

Limitations

This implementation is HW-dependent and was tested for x86_64. You will observe funny effects when HW uses VIVT caches.

If you would like to use it on different HW, you should have done some testing in advance. src/rng_buf_tests could be a start point for it.

Requirements

  1. Support for POSIX shared memory
  2. Proper HW (cache-controller)

Build

 $ cmake . && make

Example

Use src/rng_buf_tests.cc as an example.

Multi-threading

There is a special version of library for the multi-threaded apps. This version has suffix 'mt' and avoids some rare race-condition. Threads synchronization is a responsibility of app.

rng_buf's People

Contributors

vitalyvch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.