Skip to content

Commit 3c012fe

Browse files
authored
Added C++ library link
1 parent baa675f commit 3c012fe

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

README.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,19 @@ This is a simple ring (FIFO) buffer library for the Arduino. It is written in va
55
## Project History
66
I needed a way to buffer sensor events for a group engineering IOT project that I was working on at Cornell. We needed to record changes in IR trip wires that happened in ms timeframes, and tight loop polling was not working. We needed interrupts and a buffering library. I couldn't find any suitable Arduino Libraries that could buffer any sized object, so I wrote my own.
77

8-
I decided to give object oriented programming a shot using only C (no C++) with this library, of course, it still compiles with C++ compilers such as in the Arduino IDE. Using C structs and function pointers, the library creates RingBuf objects that are complete with their own methods and attributes. Note that every method (except constructor), takes a `RingBuf *self` pointer. This is the equivalent of the `this` pointer in C++, but the C++ compiler automatically passes it behind the scenes. For this library, you must manually pass a the `RingBuf *self` pointer as the first argument.
9-
10-
## FAQ's
11-
<dl>
12-
<dt>Can I buffer C++ objects?</dt>
13-
<dd>The library only shallow copies objects into the buffer, it will not call the copy constructor. For many C++ objects this works fine, but if you require a deep copy you will have to look into libraries that supports something like C++ templates. And to be honest, you shouldn't be doing deep copies on a microcontroller or you could get random freezes from memory fragmentation.</dd>
14-
</dl>
15-
16-
## But I like C++'s object syntax...
17-
18-
Fine. I reluctantly wrapped the C stuff in a C++ class called `RingBufC`. All the methods are the same, except you no longer have to pass the this/self pointer. You can use either.
8+
I decided to give object oriented programming a shot using only C (no C++) with this library, of course, it still compiles with C++ compilers such as in the Arduino IDE. Using C structs and function pointers, the library creates RingBuf objects that are complete with their own methods and attributes. Note that every method (except constructor), takes a `RingBuf *self` pointer. This is the equivalent of the `this` pointer in C++, but the C++ compiler automatically passes it behind the scenes. For this library, you must manually pass a the `RingBuf *self` pointer as the first argument, like this:
199

2010
```c++
21-
// If you want to use C...
2211
char *mystr = "I like C";
2312

2413
RingBuf *buf = RingBuf_new(sizeof(char*), 100);
2514
buf->add(buf, &mystr);
2615
```
2716
28-
```c++
29-
// If you want to use the C++ wrapper
30-
char *mystr = "C++ has pretty object.method() syntax";
31-
32-
RingBufC = buf(sizeof(char*), 100);
33-
buf.add(&mystr);
34-
```
17+
## What about C++ templates?
3518
19+
I recently created a C++ alternative to this library that utilizes the power of C++ templates, now you can perform deep copies of objects.
20+
Check it out: [C++ alternative library] (https://github.com/wizard97/Embedded_RingBuf_CPP).
3621
3722
## Use Cases
3823

0 commit comments

Comments
 (0)