aboutsummaryrefslogtreecommitdiff
path: root/buffer.h
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-11-19 22:58:57 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-11-19 22:58:57 +0100
commita62859dd9ba460f946c37ed1bcf971f0167a3852 (patch)
treefbef37aaed7c1ef772f5762d9e40fa7b32dc392e /buffer.h
parentd4246cb8a14c77926a864d6e896b1e46332a16a1 (diff)
downloadvis-a62859dd9ba460f946c37ed1bcf971f0167a3852.tar.gz
vis-a62859dd9ba460f946c37ed1bcf971f0167a3852.tar.xz
buffer: add some comments to clarify allocation strategy
Closes #116
Diffstat (limited to 'buffer.h')
-rw-r--r--buffer.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/buffer.h b/buffer.h
index 4c5ae33..0dc2dc6 100644
--- a/buffer.h
+++ b/buffer.h
@@ -5,15 +5,16 @@
#include <stdbool.h>
#include "text.h"
-typedef struct { /* a dynamically growing buffer storing arbitrary data */
+/* a dynamically growing buffer storing arbitrary data, used for registers/macros */
+typedef struct {
char *data; /* NULL if empty */
size_t len; /* current length of data */
size_t size; /* maximal capacity of the buffer */
} Buffer;
-/* initalize a (stack allocated) Buffer insteance */
+/* initalize a (stack allocated) Buffer instance */
void buffer_init(Buffer*);
-/* relase/free all data stored in this buffer, reset size to zero */
+/* release/free all data stored in this buffer, reset size to zero */
void buffer_release(Buffer*);
/* reserve space to store at least size bytes in this buffer.*/
bool buffer_grow(Buffer*, size_t size);
@@ -31,8 +32,9 @@ bool buffer_insert0(Buffer*, size_t pos, const char *data);
bool buffer_append(Buffer*, const void *data, size_t len);
/* append NUl-terminated data */
bool buffer_append0(Buffer*, const char *data);
-
+/* insert new data at the start of the buffer */
bool buffer_prepend(Buffer*, const void *data, size_t len);
+/* prepend NUL-terminated data */
bool buffer_prepend0(Buffer*, const char *data);
#endif