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
+45-1Lines changed: 45 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ A ring buffer is used when passing asynchronous io between two threads. In the c
17
17
### Constructor
18
18
19
19
```
20
-
RingBuf* RingBuf_new(int size, int len);
20
+
RingBuf *RingBuf_new(int size, int len);
21
21
```
22
22
23
23
Creates a new RingBuf object of len elements that are size bytes each. A poetinter to the new RingBuf object is returned on success. On failure (lack of memory), a null pointer is returned.
@@ -30,3 +30,47 @@ int RingBuf_delete(RingBuf *self);
30
30
```
31
31
32
32
Deletes the RingBuf, and frees up all the memory associated with it.
33
+
34
+
## Methods
35
+
36
+
37
+
### add()
38
+
39
+
```
40
+
int add(RingBuf *self, void *object);
41
+
```
42
+
43
+
Append an element to the buffer, where object is a pointer to object you wish to append. Returns -1 on a full buffer. On success, returns the position (index) in the buffer where the element was added.
44
+
45
+
### peek()
46
+
47
+
```
48
+
void *peek(RingBuf *self, unsigned int num);
49
+
```
50
+
51
+
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.
52
+
53
+
### pull()
54
+
55
+
```
56
+
void *pull(RingBuf *self, void *object);
57
+
```
58
+
59
+
Pull the first element out of the buffer. The first element is copied into the location pointed to by object. Returns a NULL pointer if the buffer is empty, otherwise returns object.
0 commit comments