aboutsummaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-11-20 15:35:37 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-11-20 15:35:37 +0100
commit0667089d47dd0cee5bda83965ff6bbdc2e4fd288 (patch)
tree1cfd727134f641a55238e5bead743ad23c489a74 /buffer.c
parent697bc0ebc8178488cdb837b584b47d965b421b48 (diff)
downloadvis-0667089d47dd0cee5bda83965ff6bbdc2e4fd288.tar.gz
vis-0667089d47dd0cee5bda83965ff6bbdc2e4fd288.tar.xz
buffer: tweak memory allocation strategy
Do not simply double the requested size. Instead take the maximum of - the requested size - double the current buffer size This will use less memory for large register operations (e.g. deleting the whole file).
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/buffer.c b/buffer.c
index 1577e6f..a0b60e2 100644
--- a/buffer.c
+++ b/buffer.c
@@ -15,10 +15,7 @@ bool buffer_grow(Buffer *buf, size_t size) {
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;
+ size = MAX(size, buf->size*2);
char *data = realloc(buf->data, size);
if (!data)
return false;