[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RfC PATCH 03/10] vnc: make the Buffer capacity increase in
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [RfC PATCH 03/10] vnc: make the Buffer capacity increase in powers of two |
Date: |
Thu, 24 Sep 2015 10:42:01 +0200 |
From: Peter Lieven <address@hidden>
This makes sure the number of reallocs is in O(log N).
Signed-off-by: Peter Lieven <address@hidden>
[ rebased to io/buffer.c ]
Signed-off-by: Gerd Hoffmann <address@hidden>
---
io/buffer.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/io/buffer.c b/io/buffer.c
index 68ae68d..6aa06e7 100644
--- a/io/buffer.c
+++ b/io/buffer.c
@@ -20,10 +20,13 @@
#include "io/buffer.h"
+#define QIO_BUFFER_MIN_INIT_SIZE 4096
+
void qio_buffer_reserve(QIOBuffer *buffer, size_t len)
{
if ((buffer->capacity - buffer->offset) < len) {
- buffer->capacity += (len + 1024);
+ buffer->capacity = pow2ceil(buffer->offset + len);
+ buffer->capacity = MAX(buffer->capacity, QIO_BUFFER_MIN_INIT_SIZE);
buffer->buffer = g_realloc(buffer->buffer, buffer->capacity);
}
}
--
1.8.3.1
- [Qemu-devel] [RfC PATCH 00/10] vnc buffer handling, Gerd Hoffmann, 2015/09/24
- [Qemu-devel] [RfC PATCH 03/10] vnc: make the Buffer capacity increase in powers of two,
Gerd Hoffmann <=
- [Qemu-devel] [RfC PATCH 04/10] io: add qio_buffer_init, Gerd Hoffmann, 2015/09/24
- [Qemu-devel] [RfC PATCH 01/10] io/ makefile fluff, Gerd Hoffmann, 2015/09/24
- [Qemu-devel] [RfC PATCH 06/10] io: add qio_buffer_move, Gerd Hoffmann, 2015/09/24
- [Qemu-devel] [RfC PATCH 09/10] vnc: kill jobs queue buffer, Gerd Hoffmann, 2015/09/24
- [Qemu-devel] [RfC PATCH 07/10] io: add qio_buffer tracing, Gerd Hoffmann, 2015/09/24
- [Qemu-devel] [RfC PATCH 08/10] name vnc buffers, Gerd Hoffmann, 2015/09/24