aboutsummaryrefslogtreecommitdiff
path: root/buffer.c
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.c
parentd4246cb8a14c77926a864d6e896b1e46332a16a1 (diff)
downloadvis-a62859dd9ba460f946c37ed1bcf971f0167a3852.tar.gz
vis-a62859dd9ba460f946c37ed1bcf971f0167a3852.tar.xz
buffer: add some comments to clarify allocation strategy
Closes #116
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/buffer.c b/buffer.c
index 6a16a7b..1577e6f 100644
--- a/buffer.c
+++ b/buffer.c
@@ -11,9 +11,12 @@ void buffer_init(Buffer *buf) {
}
bool buffer_grow(Buffer *buf, size_t size) {
+ /* ensure minimal buffer size, to avoid repeated realloc(3) calls */
if (size < BUF_SIZE)
size = BUF_SIZE;
if (buf->size < size) {
+ /* if this is not the first allocation i.e. the buffer is
+ * currently full, double the size to avoid memory pressure */
if (buf->size > 0)
size *= 2;
char *data = realloc(buf->data, size);