Skip to content

Commit dc627ab

Browse files
committed
Finished README
1 parent 0885867 commit dc627ab

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A ring buffer is used when passing asynchronous io between two threads. In the c
1717
### Constructor
1818

1919
```
20-
RingBuf* RingBuf_new(int size, int len);
20+
RingBuf *RingBuf_new(int size, int len);
2121
```
2222

2323
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);
3030
```
3131

3232
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.
60+
61+
62+
### isFull()
63+
```
64+
bool isFull(RingBuf *self);
65+
```
66+
67+
Returns true if buffer is full, otherwise false.
68+
69+
70+
### isEmpty()
71+
72+
```
73+
bool isEmpty(RingBuf *self);
74+
```
75+
76+
Returns true if buffer is empty, false otherwise.

0 commit comments

Comments
 (0)