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
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,12 @@ I needed a way to buffer sensor events for a group engineering IOT project that
7
7
8
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
9
10
+
## FAQ's
11
+
1. Can I buffer C++ objects?
12
+
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.
13
+
14
+
2. Does this library support non AVR platforms?
15
+
Currently no, see [#2](https://github.com/wizard97/ArduinoRingBuffer/issues/2). If someone knows of a portable replacement for the `ATOMIC_BLOCK(ATOMIC_RESTORESTATE){}` macro please let me know.
10
16
11
17
## But I like C++'s object syntax...
12
18
@@ -22,7 +28,7 @@ buf->add(buf, &mystr);
22
28
23
29
```
24
30
// If you want to use the C++ wrapper
25
-
char *mystr = "C++ has pretty object.method() syntax";
31
+
char *mystr = "I like C++";
26
32
27
33
RingBufC = buf(sizeof(char*), 100);
28
34
buf.add(&mystr);
@@ -86,7 +92,7 @@ Append an element to the buffer, where object is a pointer to object you wish to
86
92
void *peek(RingBuf *self, unsigned int num);
87
93
```
88
94
89
-
Peek at the num'th element in the buffer. Returns a void pointer to the location of the num'th element. If num is out of bounds or the num'th element is empty, a NULL pointer is returned. Cast the result of this call into a pointer of whatever type you are storing in the buffer. Note that this gives you direct memory access to the location of the num'th element in the buffer, allowing you to directly edit elements in the buffer. Note that while all of RingBuf's public methods are thread safe (including this one), directly using the pointer returned from this method is not thread safe. To use this returned pointer safely, disable interrupts first with `noInterrupts()`, do whatever you need to do with the pointer, then you can reenable interrupts by calling `interrupts()`.
95
+
Peek at the num'th element in the buffer. Returns a void pointer to the location of the num'th element. If num is out of bounds or the num'th element is empty, a NULL pointer is returned. Cast the result of this call into a pointer of whatever type you are storing in the buffer. Note that this gives you direct memory access to the location of the num'th element in the buffer, allowing you to directly edit elements in the buffer. Note that while all of RingBuf's public methods are thread safe (including this one), directly using the pointer returned from this method is not thread safe. If there is a possibility an interrupt could fire and remove/modify the item pointed to by the returned pointer, disable interrupts first with `noInterrupts()`, do whatever you need to do with the pointer, then you can reenable interrupts by calling `interrupts()`.
0 commit comments