You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-19Lines changed: 4 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,34 +5,19 @@ This is a simple ring (FIFO) buffer library for the Arduino. It is written in va
5
5
## Project History
6
6
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.
7
7
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:
19
9
20
10
```c++
21
-
// If you want to use C...
22
11
char *mystr = "I like C";
23
12
24
13
RingBuf *buf = RingBuf_new(sizeof(char*), 100);
25
14
buf->add(buf, &mystr);
26
15
```
27
16
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?
35
18
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).
0 commit comments