Share My Creation Circular Buffer Class For Integer Arrays

Hi,

I adapted a circular buffer type originally written in C and C++ by Phillip Johnston of Embedded Artistry. Circ Buffer P Johnston

The circular buffer uses a list which expands to a maximum size as entries are added then persists with items handled with list.set and list.get.

To use it you, instantiate an object, intialise it with the maximum size and number of integer variables per record.

You push items on to the list and pop them off.

You can also peek at data pointed to by the output pointer (tail) without removing data.

You can also do a try_put which will only add another record if there is room.

I have attached a small test program so you can see how to use it.

I would have liked to make it more general so arbitrary objects could be pushed and popped, but I didn't know how to do that and I don't have any time to figure it out at the moment.

Of course it could also be used in all B4x environments, but I haven't tested it in them.

I hope someone finds it useful.

Rob
 

Attachments

  • CircularBufferTest_V1.zip
    43.3 KB · Views: 141
Top