[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 06/16] vnc: palette: use a pool to reduce memory
From: |
Corentin Chary |
Subject: |
[Qemu-devel] [PATCH v3 06/16] vnc: palette: use a pool to reduce memory allocations |
Date: |
Fri, 4 Feb 2011 09:05:58 +0100 |
We now that the palette will never have more than 256
elements. Let's use a pool to reduce malloc calls.
Signed-off-by: Corentin Chary <address@hidden>
---
ui/vnc-palette.c | 18 ++----------------
ui/vnc-palette.h | 3 ++-
2 files changed, 4 insertions(+), 17 deletions(-)
diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c
index bff6445..c47420b 100644
--- a/ui/vnc-palette.c
+++ b/ui/vnc-palette.c
@@ -63,23 +63,9 @@ VncPalette *palette_new(size_t max, int bpp)
void palette_destroy(VncPalette *palette)
{
- int i;
-
if (palette == NULL) {
- return ;
+ qemu_free(palette);
}
-
- for (i = 0; i < VNC_PALETTE_HASH_SIZE; i++) {
- VncPaletteEntry *entry = QLIST_FIRST(&palette->table[i]);
- while (entry) {
- VncPaletteEntry *tmp = QLIST_NEXT(entry, next);
- QLIST_REMOVE(entry, next);
- qemu_free(entry);
- entry = tmp;
- }
- }
-
- qemu_free(palette);
}
int palette_put(VncPalette *palette, uint32_t color)
@@ -97,7 +83,7 @@ int palette_put(VncPalette *palette, uint32_t color)
if (!entry) {
VncPaletteEntry *entry;
- entry = qemu_mallocz(sizeof(*entry));
+ entry = &palette->pool[palette->size];
entry->color = color;
entry->idx = idx;
QLIST_INSERT_HEAD(&palette->table[hash], entry, next);
diff --git a/ui/vnc-palette.h b/ui/vnc-palette.h
index d0645eb..f57d0e7 100644
--- a/ui/vnc-palette.h
+++ b/ui/vnc-palette.h
@@ -34,6 +34,7 @@
#include <stdint.h>
#define VNC_PALETTE_HASH_SIZE 256
+#define VNC_PALETTE_MAX_SIZE 256
typedef struct VncPaletteEntry {
int idx;
@@ -42,7 +43,7 @@ typedef struct VncPaletteEntry {
} VncPaletteEntry;
typedef struct VncPalette {
- QObject_HEAD;
+ VncPaletteEntry pool[VNC_PALETTE_MAX_SIZE];
size_t size;
size_t max;
int bpp;
--
1.7.3.4
- [Qemu-devel] [PATCH v3 01/16] vnc: qemu can die if the client is disconnected while updating screen, (continued)
- [Qemu-devel] [PATCH v3 01/16] vnc: qemu can die if the client is disconnected while updating screen, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 02/16] vnc: don't set the quality if lossy encoding are disabled, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 03/16] vnc: add a way to get the update frequency for a given region, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 04/16] vnc: refresh lossy rect after a given timeout, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 05/16] vnc: tight: use the update frequency to choose between lossy and lossless, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 06/16] vnc: palette: use a pool to reduce memory allocations,
Corentin Chary <=
- [Qemu-devel] [PATCH v3 07/16] vnc: palette: add palette_init calls, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 08/16] vnc: palette: and fill and color calls., Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 10/16] vnc: fix uint8_t comparisons with negative values, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 09/16] vnc: Add ZRLE and ZYWRLE encodings., Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 11/16] vnc: fix lossy rect refreshing, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 12/16] bitmap: add a generic bitmap and bitops library, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 13/16] vnc: use the new generic bitmap functions, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 14/16] vnc: don't try to send bigger updates that client height, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 15/16] vnc: tight: tweak adaptive tight settings, Corentin Chary, 2011/02/04
- [Qemu-devel] [PATCH v3 16/16] vnc: add a non-adaptive option, Corentin Chary, 2011/02/04