A simple ringbuffer template implementation in C++ thatcan utilize local or shared memory.
Compile with -std=c++11 flag, there's an example threadedapp in main.cpp. One limitation of the SHM version is thatthe buffer must be statically sized. The locally allocatedversion can be allocated on the fly.
By defualt this will build a library. The header file that should be includedwhen using the FIFO is simply fifo.hpp. It can be instantiated on SHM or heap.The size of each FIFO is static. It is also lock free.
#include"fifo.hpp"#include<cstdint>#include<cstdlib>#include<iostream>#include<thread>usingringb_t = RingBuffer< std::int64_t/* buffer type*/, Type::Heap/* allocation type*/ > TheBuffer;staticvoidfunc_a(ringb_t &buffer,bool &term ){int i =0;while( ! term ) { buffer.push( i++ ); }return;}staticvoidfunc_b(ringb_t &buffer,bool &term ){while( ! term ) {int value; buffer.push( value ); std::cout << value <<"\n"; }return;}intmain(){ringb_tbuffer(100/** size **/ );boolterm(false ); std::threada( func_a,std::ref( buffer ),std::ref( term ) ); std::threadb( func_b,std::ref( buffer ),std::ref( term ) ); term =true; a.join(); b.join();return( EXIT_SUCCESS );}
- Add TCP connected ringbuffer implementation.
- Add Java implementation that can use the C/C++ allocated SHM with at least primitive types.
- Add write and read optimizations.