Efficient Ring Buffer

I need someone to guide me through making a ring buffer in arduino. I can do it with a function or use an available library but I think tha won't be efficient as I require the most speed I can get. I also think making it in C would be better in terms of sketch size and speed.

Ring buffers are easy, whether they are in C or some other language. (You didn't specify whether you meant C++, or assembly language, or something else.)
Making them really fast usually requires knowing something more, like:

  • What size are the data items? byte, int, long, long long, etc.
  • What size is the buffer? Can it be a power of 2?
  • Where is the start of the buffer? Is it allowed to be on a power of 2 boundary of the data item size?
  • Are there issues with multithreading or interrupts, such as the possibility that data might be added to the ring buffer concurrently with data being removed?
  • Do you need to check for boundary conditions such as full or empty? Nearly full? Nearly empty?

If it were up to me, I would want to make the ring buffer work correctly, and then work on the speed if necessary.

I need to learn to make it in C# as it's the fastest to process (I guess) and takes little space.

The data items are 8 bit integers for now.

Buffer size is 128 bins.

I need to know when the buffer is full to dump it on a screen and fill it up again.

I do understand the priorities to making it and tuning it.

Everything you need to know is here.

I need to learn to make it in C# as it's the fastest to process (I guess) and takes little space.

Are you sure you're in the right forum? We deal in C, C++ and occasionally assembler 'round these parts...

Cheers,
/dev

I included a ring buffer in the code in yet another software serial. Unashamedly based on the code in the Arduino Hardware Serial library.

...R

/dev : I meant C, I know the difference well, not sure why I did say C#. Thanks for the response.

Robin 2 : I'll try to comprehend your addition and come back if I don't understand anything. Thanks for the response.

youssefaly97:
I also think making it in C would be better in terms of sketch size and speed.

What is the alternative?

Perhaps if you explain your project more.

I require the most speed I can get ...

HardwareSerial uses a ring buffer, and that seems to work OK.

I'm making an oscilloscope using the arduino uno 328p, 128x64 Serial/parallel GLCD ST7565 and MCP3202 2-channel 12-Bit ADC or arduino's built-in ADC (at 8 bit 1 channel for maximum speed).

Aren't C++ and assembly alternatives ?

youssefaly97:
Aren’t C++ and assembly alternatives ?

Unless you are VERY good at assembler you are unlikely to do any better than the GCC compiler.

There are some steps you can take to view the assember code that is produced when the Arduino program is compiled. I’m afraid I have forgotten the details.

…R