summaryrefslogtreecommitdiff
path: root/frame_tvbuff.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2016-07-21 17:34:56 -0700
committerAnders Broman <a.broman58@gmail.com>2016-07-22 04:18:08 +0000
commitb2e4a7e21ce7ee8fee857ee71d51ad1ec13feb2e (patch)
tree9676cdf55d35911902b17c3a7135a52f2cd2a4ba /frame_tvbuff.c
parente3a15cfbb24b79c0225d391dc44362ac9cdcb077 (diff)
downloadwireshark-b2e4a7e21ce7ee8fee857ee71d51ad1ec13feb2e.tar.gz
Minimize allocations for frame tvbuffs and Buffers.
Try to minimize the number of times we allocate memory for Buffers and Buffer data. Change-Id: I738fdc64e571772ef4ba6335d49087277dd7b430 Reviewed-on: https://code.wireshark.org/review/16577 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'frame_tvbuff.c')
-rw-r--r--frame_tvbuff.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/frame_tvbuff.c b/frame_tvbuff.c
index 311653ce1a..9af5d2ff4d 100644
--- a/frame_tvbuff.c
+++ b/frame_tvbuff.c
@@ -69,6 +69,8 @@ frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf)
return TRUE;
}
+static GPtrArray *buffer_cache = NULL;
+
static void
frame_cache(struct tvb_frame *frame_tvb)
{
@@ -77,9 +79,14 @@ frame_cache(struct tvb_frame *frame_tvb)
wtap_phdr_init(&phdr);
if (frame_tvb->buf == NULL) {
- frame_tvb->buf = (struct Buffer *) g_malloc(sizeof(struct Buffer));
+ if G_UNLIKELY(!buffer_cache) buffer_cache = g_ptr_array_sized_new(1024);
+
+ if (buffer_cache->len > 0) {
+ frame_tvb->buf = (struct Buffer *) g_ptr_array_remove_index(buffer_cache, buffer_cache->len - 1);
+ } else {
+ frame_tvb->buf = (struct Buffer *) g_malloc(sizeof(struct Buffer));
+ }
- /* XXX, register frame_tvb to some list which frees from time to time not used buffers :] */
ws_buffer_init(frame_tvb->buf, frame_tvb->tvb.length + frame_tvb->offset);
if (!frame_read(frame_tvb, &phdr, frame_tvb->buf))
@@ -98,8 +105,7 @@ frame_free(tvbuff_t *tvb)
if (frame_tvb->buf) {
ws_buffer_free(frame_tvb->buf);
-
- g_free(frame_tvb->buf);
+ g_ptr_array_add(buffer_cache, frame_tvb->buf);
}
}